Dialogue often has to reach into your game. A line might need to play a sound, check what the player is carrying, or remember that the player has already met someone.
Yarn Spinner gives you three ways to do that:
- Commands let your Yarn Scripts tell your game to do something, like play a sound or move a character.
- Functions let your Yarn Scripts ask your game for a value, like how many coins the player has.
- Variables store values that both your Yarn Scripts and your game can read and change, like whether the player has met Rosa.
flowchart LR
yarn["Your Yarn Script"]
subgraph game["Your game"]
direction TB
audio["Audio player"]
clock["Lighthouse clock"]
inventory["Inventory"]
end
storage[("Variable Storage")]
yarn -->|"#60;#60;play_sound door_creak#62;#62;"| audio
yarn -->|"days_since_lamp_lit()"| clock
clock -.->|"12"| yarn
yarn <-->|"$has_key<br>$met_rosa"| storage
inventory -->|"sets $has_key"| storageThis node uses all three:
title: Lighthouse
---
<<play_sound door_creak>>
Rosa: The lamp's been out for {days_since_lamp_lit()} days.
<<if $has_key>>
Rosa: You found the key! Let's go up.
<<endif>>
<<set $met_rosa to true>>
===Line 3
A Command. Your game decides what
play_sound does, here playing a sound called door_creak. The dialogue can wait for it to finish. See Commands.Line 4
A Function. Your game works out the number of days, and it’s shown in the line. See Functions.
Lines 5–7
Checking a variable. Your game might set
$has_key when the player picks up the key. See Variables and Storage.Line 8
Setting a variable. Your game can read
$met_rosa later, for example to change what Rosa says next time.A Command, a Function and two variables in one node.
Variables hold the state you save and load, so a player can leave a conversation and later pick it up where they left it.
In this section
- Commands: calling your game code from Yarn, and making dialogue wait until it’s done.
- Functions: getting values from your game to use in lines and conditions.
- Putting It Together: a small scene that uses Commands and Functions together.
- Variables and Storage: reading and changing Yarn variables from GDScript, and saving and loading them.
- Smart Variables: variables that are worked out from other variables each time they’re read.
- Saliency and Storylets: how the Dialogue Runner picks one line or node when several could run.
- Custom Saliency Strategies: writing your own way to pick content from node groups and line groups.
- Async and Cancellation: waiting in Commands and Presenters without breaking skipping or pausing.