Howdy, Stranger!

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

Setting a variable if multiple conditions are met

I want to know if it is possible to set a variable depending on if a condition is met (and expand that to if multiple conditions are met).
Here is what I have so far:
<<if ($sbplank_bank is "yes") and ($sbplank_edge is "yes") and ($sbplank_tree is "yes")>><<set $serpeus_bridge = "fixed">><<endif>>
Basically I want it to check for three things, and if all of them are met, a variable gets set. Is this even a possible operation?
This is my first day with twine, so I know I don't know a lot of things. Thanks for any help!

Comments

  • The short answer is yes.

    The long answer is that you are able to test this yourself by first adding the following to a new passage and then use the Passage Editor's Passage > Test Play From Here menu option to test the passage.

    <<set $sbplank_bank to "yes">>
    <<set $sbplank_edge to "yes">>
    <<set $sbplank_tree to "yes">>
    <<set $serpeus_bridge to "yes">>
    <<set $serpeus_bridge to "broken">>

    <<if ($sbplank_bank is "yes") and ($sbplank_edge is "yes") and ($sbplank_tree is "yes")>><<set $serpeus_bridge to "fixed">><<endif>>

    Bridge is <<print $serpeus_bridge>>
    You can change any of the first four <<set>> macros from "yes" to "no" and then re-run the test. You may note that I change the equals sign to the word "to" when setting the $serpeus_bridge within your conditional statement, this was to make it consistent with the usage of "is" when comparing.

    Ideally you will want to assign all your variables an initial before you use them within your story/game, you should do this within the special StoryInit passage which you can create using the Story > Special Passages > StoryInit menu item.
  • I couldn't get it working for some reason, so I just made it test for all three things any time I wanted to it test for if the bridge was fixed or broken--which works. Thanks for telling me about that StoryInit page! I thought I had to put all the variables on the Start page, haha, so I'm glad I have a seperate page to make things easier. I did copy your command and it worked when I tested it by itself, but for some reason it wouldn't work in the context I needed it to. Perhaps it have something to do with the fact that I go back to a certain passage? I don't know to be honest. Thanks for the help though, you helped a lot!
Sign In or Register to comment.