Howdy, Stranger!

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

Help with age

edited July 2017 in Help! with 2.0
Hey all, New to programming. I'm trying to set up a variable age with a fixed age corresponding to it.

I'm using Twine 2.1.3 and Sugarcube 2.18.0

For example:
What's your FIRST name? <<textbox '$fname' '' autofocus>>
What's your LAST name? <<textbox '$Lname' '' autofocus>>
You are how old: <<textbox '$age' '' autofocus>>

<<set $dadage to 22>>

Then the next passage would read:

Your dad's FIRST name is: <<textbox '$dad' '' autofocus>>
He is <<set $dadage to$dadag +$age>> $dadage years old.

Whenever it gives a result. For example if I input 20 to my age text box, the result comes out as the $dadage comes out as 2022.

I assume this is because by entering the age into a text box it is applying "20" around it and thus adding the two numbers together as text hence 20 + 22 = 2022.
Is there a way to have someone enter a numerical variable that keeps it's numeric form so that additional will be arithmetic rather than combination?

Thanks all!

Comments

  • edited July 2017
    Use parseInt(). More information can be found at this post.

    Also, you misspelled the variable name $dadage as $dadag in your example, so you might want to double check your code.
  • Chapel, you're my hero!!!! Perfect and you were correct about the typo. This damn Colorado air does things to you.

    Thank you SOOOOOO much!
Sign In or Register to comment.