Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Determining the character length of strings (sugarcane)

So I want the player to be able to enter in some text, and I don't mind them putting in an arbitrarily large number of characters, but if what they enter is more than, say, 15 or 20 for the game to stead assign a different string to the variable. Is there a way of doing this without limiting the actual amount of characters the player types into the text input box?

Thank you in advance for your help.

Comments

  • You can determine the number of characters in a javascript string by checking it's length property.

    note: the following is in TWEE notation, lines starting with two colons indicate a new passage, the text on the same line as the two colons is the new passage's title.

    :: Start
    <<set $var to "">>
    Your name? <<textinput $var "[[Submit|Answer]]">>


    :: Answer
    Your name is: <<print $var>>
    Characters: <<print $var.length>>
Sign In or Register to comment.