Skip to main content

Using Variables

Variables allow you to store data that can change based on the player's actions and influence the storyline's progression. Last time, we saved our protagonist's choice and introduced a health variable. Now, let's talk about how to use variables in your story.

Let’s assume that at the end of our escape, everything went well, and it’s time to start the first mission. Since this is a new logical block, let’s create a new file called mission.yarn and add a node with a checkpoint_name.

title: mission
checkpoint_name: "First Mission"
---
===

At the end of the nodes in the escape.yarn file, we’ll add the command <<jump mission>> to link them to the new node.

Callbacks

Callbacks are a way to show the player that their actions are influencing the story, even if it’s not entirely true. Let’s add some callbacks to our story.

For example, we can mention the path that was chosen at the beginning of the story. To do this, add the following text at the beginning of the mission node:

title: mission
checkpoint_name: "First Mission"
---
<<if $escape_choice == "ventilation">>
Thanks, escaping through the ventilation was a good move.
<<elseif $escape_choice == "scaffolding">>
Next time, avoid climbing down the scaffolding. That was close.
<<endif>>

===

Here, we use the <<if>> structure to check the value of the escape_choice variable and show different messages based on the result. This doesn’t affect the plot, but it helps the player feel more engaged in the story.

Response Options

...
So, should we start preparing for the next mission?
-> Send me the operation plan
-> First, go to the medbay to recover <<if $health < 100>>
Ok, I’ll be back soon.
<<set $health = 100>>
<<wait 10>>
All set, I’ll send you the operation details now.

In this example, we added a response option that depends on the value of the health variable. If the agent’s health is below 100, we can send them to the medbay to recover. After that, they can continue with the mission. The player won’t see this option if the agent's health is already full. Additionally, we didn’t create a separate node for this action since it’s a short event. Writing it directly under the response option doesn’t affect code readability.

These are simple examples of how to work with variables. You can fine-tune the storyline by adding more variables and conditions. For instance, you could add a money variable and offer different actions based on its value. Or introduce a weapon variable that alters the story depending on the agent’s equipment. The possibilities are endless, allowing you to craft unique and engaging narratives.