Howdy, Stranger!

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

Player entered number

I know you can use <<textinput $name>> to change the 'name' variable...

Is there something similar for numbers?
I have tried numberinput, intergerinput, arrayinput... I guess shooting in the dark can only work so often haha.
I know I can use radio buttons and the such to set this manually... but I am expecting this may need to go from 1 to 50 or so... or even more if someone wants to try and break the values haha

Comments

  • You need to state which story format you are using, as answers can be different for each one. Because you listed the <<textinput>> macro (and not <<textbox>>) I am going to assume you are using one of the Twine 1 built-in story formats like Sugarcane.

    The <<textinput>> macro can be used to input Text, Number, or Date data types although you will need to convert the value entered into a number or date yourself.

    The following example will ask the reader to enter their age, it will then do the following:
    a. Check to make sure the reader actually entered a value.
    b. Check that the String value entered is numerical using Javascript's isNaN() function.
    c. Convert the String into an integer using Javascript's parseInt() function.

    1. Start passage
    <<set $age to "">>
    
    Enter age: <<textinput $age [[Submit|Check Age]]>>
    
    2. Check Age passage
    <<if $age is "">>
    No value was entered.
    <<elseif isNaN($age)>>
    The value entered is not numerical: <<print $age>>
    <<else>>
    <<set $age to parseInt($age)>>
    Your age is <<print $age>>
    <<endif>>
    
    notes:
    a. Javascript has other functions/methods to convert String values into other data types.
    b. HTML5 has more input types than just text and although it is possible to use these inputs in a Twine story you will need to use custom Javascript code to transfer the value entered into $variable storage.
  • edited November 2015
    ah, yes; I am using 1.4.
    Sorry about that. I check which thread it's in myself since the two are so different.

    I read up on some java and (after seeing yours worked) I tried:
    <<set $string to Number($string)>>
    
    and that seems to work too!
    Looks like Java might be my next obstacle

    Thanks for the NaN tip. I can try this to verify:
    <<if isNaN($number)>> <<print>>"Try again"<<endif>>
    

    Thank you so much. Now I know I need to Java!

    (I can't seem to mark your answer as having solved my problem :S)
  • zededd wrote: »
    ah, yes; I am using 1.4.
    Sorry about that. I check which thread it's in myself since the two are so different.
    1.4 is the version of Twine you are using, it comes with three built-in story formats: Sugarcane, Jonah, and Responsive.

    To check/change which Story Format will be used when you test/build your story HTML file use the Story > Story Format menu options. The Story Format defines the default features and look of your story.
  • Now that shows my inexperience...
    Sorry for that. I honestly thought the story format was something like a built-in programming language that only varied between V1 and V2

    I'm using Sugarcane apparently (rotting my teeth, and my brain at the same time XD)

    Thank you again. I apologise for my ignorance, I should have researched that a bit sooner
Sign In or Register to comment.