Twine Version: Twine 2.3.16 Story Format: SugarCube 2.36.1
Hey,
back again with another question.
I want to use a textbox input as a number later on.
So using this wouldn’t really work:
Input a number here:
<<textbox "$yournumber" "">>
Cause I want to use the input like that later on:
<<if $yournumber gte 20>>
Show this text
<<elseif $yournumber lt 20>>
Show other text
<</if>>
How do I get my textbox-input to be saved as a usable number?
And how do I make sure the input really is a number when put in the textbox in the first place?
If you only want numbers, then instead of a <<textbox>> macro, you’d be better off using a <<numberbox>> macro.
If you’d like to limit the range of values, there isn’t an easy way to do that within the <<numberbox>>, but you could “clamp” the value when you exit the passage, like this:
That example uses the .clamp() method to limit the value of that variable to a minimum of 0 and a maximum of 100.
Alternately, you could display an error message if they chose something outside of the allowed range, like this:
<<link "Link text">>
<<if $numberVar < 0 || $numberVar > 100>>
<<replace "#errmsg">>
''Error:'' Value must be a number from 0 to 100.
<</replace>>
<<else>>
<<goto "Passage name">>
<</if>>
<</link>>
<span id="errmsg"></span>
That will cause an error message to be displayed in the <span> under the link if they click on the link while the number is outside the allowed range. Otherwise the link takes them to the next passage.
The reader will choose an age between 18 and 25. As I didn’t put quote marks, it’s a number. If for some reason I need the age to be a character value, I would go with <<option "23">>.
@HiEv
Thats exactly what I was searching for.
I looked up so much about textbox stuff without even thinking about a numberbox.
Kinda embarrassing.
Thank you! @souppilouliouma
The listbox doesn’t really fit in for the specific thing I’m trying to do, but it will come in handy later on for sure.
Thank you