Count the number of characters in a variable

0 favourites
  • 10 posts
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • Hey, I'm a french user of Construct 2. I'm making a fan gambe about Undertale.

    In a layout, the player should be able to choose the name of the characters. Each letter set the variable of the name of the human to "HumanName &" LETTER "".

    Now the problem is that I would like the variable to be no more than 6 letters.

    If possible, I would also like the "Delete" button to delete a letter from the variable.

    I'm waiting impatiently for your answer.

  • I'm not sure I understood correctly but you can use the system expression len to get how many characters.

    len(text)

    Return the number of characters in text.

    you can also use this in a condition to limit the amount of characters you can enter.

  • I'm not sure I understood correctly but you can use the system expression len to get how many characters.

    len(text)

    Return the number of characters in text.

    you can also use this in a condition to limit the amount of characters you can enter.

    I have already tested using len in the following way: "len (HumanName, 6)" 6 being the maximum number of letters I want to have, not one more. But she did not work.

  • Actually I had used left (variable, 6) on "compare variable not equal to", how to use len (text)?

  • + (no conditions)

    -> TextInput: Set text to left(TextInput.Text, 6)

    -> System: Set charname to TextInput.Text

    -> Text: Set text to charname

    Something like this should work.

  • + System: len(TextInput.Text) > 5

    -> TextInput: Set text to left(TextInput.Text, 6)

    -> System: Set charname to TextInput.Text

    Something like this should work.

    Thanks, I will test it later

  • Updated it a little bit... works better.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • + (no conditions)

    -> TextInput: Set text to left(TextInput.Text, 6)

    -> System: Set charname to TextInput.Text

    -> Text: Set text to charname

    Something like this should work.

    What is "charname"? I do not find this event.

  • Thank you, I was able to solve my problem. You would have no solution for my second problem? If that does not bother you of course.

  • charname is a global variable i created. That uses a string to store the character name.

    You can use an instance variable instead if you like. Just make sure you set it to string. But global variable is better since it can be remembered across layouts.

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