A quick list of every fundamental piece of Yarn Spinner syntax.

Yarn Spinner Cheat Sheet

Yarn
title: Bakery
---
<<declare $gold = 12>>
Baker: Fresh pies! You've got {$gold} gold.
-> Buy a pie. <<if $gold >= 10>>
    <<set $gold = $gold - 10>>
    Baker: Enjoy it. You've got {$gold} gold left.
-> Just looking.
    <<jump Street>>
===

title: Street
---
You step back out into the rain.
===
A small script that uses a lot of Yarn. Run it, then look up each part in the cards below.
01

Nodes and lines

title: Start
Names the node. Every node needs one.
tags: intro
Any other header you want.
---
Ends the header. The body starts here.
===
Ends the node.
Narrator: Hello!
A line said by Narrator.
Hello!
A line with no speaker.
// A note
A comment. Never shown.
Nodes and Lines
02

Options

-> Yes, please.
An option. Options in a row are shown together.
-> Open the door. <<if $has_key>>
Only available while $has_key is true.
-> Ask again. <<once>>
Can only be picked once.
-> Yes, please.
    Narrator: Great.
-> No, thanks.

Indented lines under an option only run if that option is picked.

Options
03

Moving between nodes

<<jump Cave>>
Go to the node titled Cave.
<<detour Side>>
Run Side, then come back here.
<<return>>
Leave a detour early.
<<stop>>
End the dialogue.
Jump Command
04

Variables

<<declare $gold = 0>>
Create a variable, with its starting value.
<<set $gold to 10>>
Change it. = works instead of to.
<<set $gold = $gold + 5>>
Set it from an expression.
Narrator: {$gold} gold.
Show its value in a line.
<<declare $rich = $gold > 100>>
A smart variable, worked out again each time it’s read.

Variables hold a number, a string, a boolean or an enum case, and can’t change type.

Variables
05

Operators

+ - * / %
Maths. % is the remainder.
== !=
Equal, not equal.
< > <= >=
Less than, greater than, and so on.
and or xor not
Logic. Or write &&, ||, ^ and !.
( )
Work this part out first.
Operators
06

Flow control

<<if $gold >= 10>>
    Baker: Here's your pie.
<<elseif $gold >= 5>>
    Baker: Almost.
<<else>>
    Baker: No pie for you.
<<endif>>

The first branch whose condition is true runs. elseif and else are optional.

Flow Control
07

Once

<<once>> … <<endonce>>
Runs the first time only.
<<once>> … <<else>> … <<endonce>>
The first part the first time, the else part after that.
<<once if $is_hero>>
Once, and only while the condition is true.
Guard: Who are you? <<once>>
A line that runs once.
Once
08

Line and node groups

=> Guard: Halt!
A line group. One available line is picked.
=> Guard: Hail, hero! <<if $is_hero>>
Only available while the condition is true.
when: $gold > 5
In a header. Makes the node part of a node group, which can run while the condition is true. Nodes in a group share a title.
when: once
The node can run once.
when: always
The node can always run.
Node Groups
09

Enums

<<enum Mood>>
  <<case Happy>>
  <<case Grumpy>>
<<endenum>>

<<declare $mood = Mood.Happy>>
<<set $mood to .Grumpy>>

An enum variable holds exactly one of its cases. .Grumpy is short for Mood.Grumpy.

Enums
10

Commands

<<wait 2>>
Pause for 2 seconds.
<<stop>>
End the dialogue.
<<shake_camera>>
Anything else goes to your game to handle.
Commands
11

Functions

visited("Cave")
Has Cave run before?
visited_count("Cave")
How many times has Cave run?
dice(6)
A random whole number, 1 to 6.
random()
A random number, 0 to 1.
random_range(1, 10)
A random number, 1 to 10.
min(a, b) max(a, b)
The smaller, or larger, of two numbers.
round(n) floor(n) ceil(n)
Rounding. Also round_places, int, inc, dec and decimal.
string(v) number(v) bool(v)
Convert to another type.

Use a function in an expression, or in a line: You rolled {dice(6)}! Your game can add its own.

Functions
12

Tags and markup

Hello! #happy
A tag your game can read.
Hello! #line:abc123
A fixed line ID, for localisation and voice-over.
[wave]Hello[/wave]!
Markup your game can style or animate.
\[Not markup\]
Square brackets shown as text.
Markup