Create a variable in a link

Now that you know how to create links and variables, let’s combine those two. Remember our examples about the door.

This is how it works:

  1. You need everything you learned in the section about links and the section about variables.
  2. The difference: Instead of the instruction <<set>> to create the variable, you use square brackets: []
  3. This is how it looks:
    [[Open door][$door to "You open the door, but it is locked."]]
    or
    [[Open door|Scene 201][$door to true]]

2. Watch how it's done

3. Start writing yourself

  1. Open a passage.
  2. Create a variable in a link and store information in the variable.

You can copy the following samples and paste them into your story. In the first sample you simply have to write the variable name to show the infromation stored in it. In the second sample you have to add the instruction: <<if>><</if>>

[[Go right][$text to "You went right."]]
[[Go left|Passage 2][$left to true]]

4. Be aware of this

To create a variable in a link, you do not use <<set>> but square bracktes: []

5. Try it out with the sample story

To better understand this topic, you can look at the sample story from the Introduction section. Download and import it here if you have not done so yet.

  1. Open the story.
  2. Locate and open the passage called "Links with Variables."
    Screenshot of 3 passages in Twine.
  3. You can now see the links with the variables stored in it.
    Screenshot of how to make a link with title of a passage and a variable in Sugarcube 2.

Takeaways

Use square brackets to create a variable in a link: []