Locked Door & Key (and a bonus death!)
How to use conditionals in TWINE
How to use conditionals in TWINE
As discussed on the main page for this section, this is done using variables. This page will take you through the process of creating a locked door and show you how it might be unlocked. In the case of a encountering a locked door, if you don't have the item (e.g., the key) you will get one message (e.g., This door is locked. Looks like you need to go find a key!) and something happens or doesn't happen (e.g., the door stays locked).
On the other hand, if you do you may get a different message (e.g., You try your key in the door and the locks clicks.) have the item happens (e.g. The door opens with an ominous creak.). The simple 4-passage IF pictured just below is an example of the Locked Door scenario. You can also find the game itself at the bottom of this page.
A locked door, a key, and a passage of death!
To create a locked door story, you need a starting point in your story (typically the first passage--titled The Quest below) where the key variable is set to false, as you can see below.
(set: $key to false)
In this story, if someone goes to the Passage titled The key to success they'll encounter this variable information:
(set: $key to true)
This means that as soon as they enter the room they are given the key. In this case, they also get the following message: "As you enter the dark room you trip over something. Dang! You reach down and discover a key. Hmmmm, where could you use this?"
If the player goes to the Passage titled room 1: A locked door with the key it will cause the code below to trigger a message: "You put the key in the mysterious door and Blingo!!"
(if: ($key is true))
[you put the key in the mysterious door and Blingo!!]
However, if they don't have the key they get a different message: "This door seems pretty locked to me. Better go find a key!
(else:) [This door seems pretty locked to me. Better go find a key!]
As mentioned, this story also may result in death via the passage titled A quick death (I'd hope your own story would not be quite so obvious!) via the code below:
=><=
###Game over.
=><=
Looks like this was a really bad room to visit. The good news is that you can try again!
(link: "Restart")[(reload:)]
See how all of this works together in the embedded IF just below.