How do I see all of a string in a textInput and add spaces?

0 favourites
From the Asset Store
Spaces Ambience contains 102 Sounds: 53 track and 49 sounds
  • I've explained this earlier:

    If your string is 100 characters long, and you start from 3 to 100, by the time you reach 100th character, the string will be around 130 characters long, because you are adding spaces after every 3rd character. So the loop will stop at 100 and the remaining portion (30 last characters) of the string will not be processed.

    If you run your loop in reverse, you avoid this issue.

    .

    Another option would be using a While loop, it will run until the full string is processed, even if it grows or shrinks:

    Local variable i=0
    While i<len(s)
    .....(process the string)
    .....Add 1 to i
    
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I understood that once I knew you couldn't update start/end index once the loop starts. I was asking why the total of loops ran isn't the same in 'len(s) to 3' and '3 to len(s)'. I thought both would run the same amount of times. How is one giving more than the other?

    I wish how things worked were in the manual in more detail, it would prevent a lot of posts. It would be great to know how it works, but I can just use a while.

  • I was asking why the total of loops ran isn't the same in 'len(s) to 3' and '3 to len(s)'.

    It is the same! In both cases with 100 characters in the string, the loop will run 98 times.

    But if you start the loop from 3 to 100, at the end of the loop your loopindex will be at position 100, however the string will already be 130 characters long (because you've added ~30 spaces to it). So the remaining 30 characters at the end of the string will be left unprocessed.

  • I understand, that is what I needed.

    If you start at 100 and loop to 3 then the space isn't counted when it is added.

    If you start at 3 and loop to 100 then the spaces are counted and then the loop doesn't get to run enough times.

    You were right, you did answer that already. I must have been missing something before because it passed right by me.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)