Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    len(text) does not work for umlauts

    Bug Reporting (FUZE 4 Nintendo Switch)
    3
    7
    411
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • spikey
      spikey F last edited by

      https://fuzearena.com/help/view/len

      print("len1=",len("äöü"), " len2=",len("aou"))
      

      prints:

      len1=6 len2=3
      

      probably it checks the byte size 🤔

      1 Reply Last reply Reply Quote 0
      • spikey
        spikey F last edited by

        found a workaround: hope this is not introducing problems.

        function strLen(text)
           textLength = 0
           charLength = textWidth("a")
           textLength = int(textWidth(text) / charLength)
        return textLength
        

        example:

        print("len1=", strLen("äöü"), " len2=", strLen("aou"))
        

        prints:

        len1=3 len2=3
        
        vinicity 1 Reply Last reply Reply Quote 1
        • spikey
          spikey F last edited by spikey

          Ok, sometimes, I would still need len. For example in this case, it works very well:

          t1 = "äöüä"
          t2 = ""
          for i = 0 to len(t) loop
             t2 += t1[i]
          repeat
          print(t2)
          

          output:

          äöüä
          

          len(t1) is 8 but, the combined bytes result again in the correct string.
          So, maybe its nice for certain cases, to have a function to count the chars, and keep len() for the bytes.
          So, this is super low prio. But maybe good to know.

          1 Reply Last reply Reply Quote 0
          • Martin
            Martin Fuze Team last edited by Martin

            I know that len is in the help section for text handling but I'm not so convinced this is a bug as a missing command from the language.

            You often have len() for getting the length of arrays and the like, and then strLen() for specifically dealing with this scenario of multi-byte characters in strings.

            I'll defer to the rest of the team to decide how they want to handle this? @Luke @Jonboy @Dave @pianofire

            1 Reply Last reply Reply Quote 0
            • vinicity
              vinicity F @spikey last edited by

              @spikey said in len(text) does not work for umlauts:

              found a workaround: hope this is not introducing problems.

              function strLen(text)
                 textLength = 0
                 charLength = textWidth("a")
                 textLength = int(textWidth(text) / charLength)
              return textLength
              

              example:

              print("len1=", strLen("äöü"), " len2=", strLen("aou"))
              

              prints:

              len1=3 len2=3
              

              For some reason, when you have set the text size to 37, this function no longer works.

              textSize(37)
              print(strLen("apa"))
              

              prints 2 instead of 3. Change the text size to 36 or 38, and it works as expected!

              I used your high score code in my Space Worm game, and for no apparent reason, the high score table always displayed wrong. Took me ages to locate the problem!

              Very weird!

              spikey 1 Reply Last reply Reply Quote 0
              • spikey
                spikey F @vinicity last edited by

                @vinicity sry, to hear. Very interesting though. And glad you found the bug👍

                1 Reply Last reply Reply Quote 1
                • spikey
                  spikey F last edited by

                  @vinicity I based the strLen() now on the byte size of a character and dropped the workaround over the pixel length of a string. https://fuzearena.com/forum/topic/1439/demo-high-scores-supports-now-unicode . Dividing the total pixel length through a single character pixel length caused a rounding error at some specific text sizes and 2.99999990 resulted in a string length of 2. This wont happen anymore now.

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post