Variables are like containers that store information in your story. They help you keep track of things like choices made, items collected, or character relationships. When combined with the conditional blocks we learned about earlier, variables become powerful tools for creating dynamic, responsive stories.
To create a variable:
hasFoundKey
is better than just key
, and playerHealth
is better than h
.Let's create some variables for a simple adventure story:
Variables are "inline" blocks, which means you can use them right within your text. Here's how to display a variable's value:
Variables start empty (undefined) until you give them a value. Use the setter block to change a variable's value:
Let's create a more complex scene using our variables.
Note that the following example is intentionally a little more complicated to showcase what is possible with variables and conditional blocks. Most of the time, you will want to rely on the story diagram to handle most of the branching narratives.
Variables are Global: All variables can be accessed from anywhere in your story.
Setting Values: Variables can store:
100
or -5
)true
or false
)playerGold - 50
or friendshipLevel + 1
)Checking Values: Variables can be:
if
blocks)