Howdy, Stranger!

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

Variables and if statements

Hi everyone, I am new to twine and I am trying to set up and if/else scenario. I want the player to find a keycard, and then use the keycard to open a door. I have the <<set $numkeycard eq "true">> after the play picks up the card. But I am insure how to make the variable bring up a new passage depending on the value. Like I would like the if else statement to be able to send the player to my Open the door passage if the variable equals "true" and send the player to No keycard passage if the value equals "false". Is this possible in Twine or are variables strictly for displaying text when the variable restrictions are met. I' working in the Sugarcane format. Thank you!

Comments

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

    You should be using the to keyword to do $variable assignments, the eq keyword is used for comparison. The boolean values true/false should not be wrapped in double quotes.
    <<set $numkeycard to true>>
    <<set $alphaVar to "some value">>
    <<set $numberVar to 100>>
    
    <<if $numkeycard>>Do something<<endif>>
    <<if $alphaVar eq "some value">>Do something<<endif>>
    <<if $numberVar eq 100>>Do something<<endif>>
    

    You have two basic choices for your problem,. there are a number of advanced options but I won't list them:
    1. Conditionally show one of your two markup links based on the value of $numkeycard
    <<if $numkeycard>>[[Open the door]]<<else>>[[No keycard]]<<endif>>
    
    2. Show the same markup link but change the target passage:
    <<if $numkeycard>>[[Next|Open the door]]<<else>>[[Next|No keycard]]<<endif>>
    

    note: the above examples are assuming you are not using SugarCube, if you are then the <<endif>>'s would be replace by <</if>>s
  • Thanks alot!
Sign In or Register to comment.