why in twine 2 using sugarcube seems to skip the if statement

0 votes
asked Nov 16, 2017 by Bunburry (140 points)

Hello All,

I'm new to Twine so it might be very obvious but can't make it work.

In the previous passage I define variable $gender by typing it in (textbox) I press enter and it should lead me to one of the rooms. However, if I type "female" seems that twine just ignores it and jumps straight to else statement leading me to 'Male bathroom'.

<<if $gender is "female">>
<<goto [[Female bathroom]]>>
<<goto [[Male bathroom]]>>

Any help will be appreciated!

1 Answer

0 votes
answered Nov 16, 2017 by Charlie (6,570 points)

That code works so long as $gender is set to "female" and not (say) "Female".  If I were you I'd avoid using a textbox to enter a variable like this.

commented Nov 16, 2017 by greyelf (58,490 points)
There are a number of issues that you need to overcome when asking the Reader to enter a value in a Text-Box.

1. The Reader may not enter a value, so you will need to check for that.

2. The Reader may enter an invalid value, so you will need to check for that.
eg. you wanted "male" or "female" and they entered "1234"

3. The Reader may enter a value using mixed letter case, so you will need to check for that.

For these reasons it is generally a good idea to use links (or some sort of list based input type) when asking a Reader to select one option from a fixed set of possible choices.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.