Howdy, Stranger!

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

Help with text input

I want my game to have a text parser that sets a specific variable to the number imput, nothing fancy.

Comments

  • You need to state which story format you are using, as answers can be different for each one.

    Harlowe:
    (set: $age to (prompt: "Your age is?"))
    
    (if: $age is "" or isNaN($age))[
    	You did not enter a number, defaulting age to 18
    	(set: $age to 18)
    ]
    (else:)[
    	Convert the text (String) numerical value into a number.
    	(set: $age to (num: $age))
    ]
    
    Age is: $age
    

    SugarCube 1: Using <<textbox>> macro:
    a. Main passage:
    Your age is? <<textbox "$age" "18" "Check Age">>
    
    b. Check Age passage:
    <<if isNaN($age)>>
    	You did not enter a number, defaulting age to 18
    	<<set $age to 18>>
    <<else>>
    	Convert the text (String) numerical value into a number.
    	<<set $age to parseInt($age)>>
    <<endif>>
    
    Age is: $age
    
Sign In or Register to comment.