Yarn Cheat Sheet
The whole Yarn language on one page.
ESC
A quick list of every fundamental piece of Yarn Spinner syntax.
Yarn Spinner Cheat Sheet
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.
===Variables
A small script that uses a lot of Yarn. Run it, then look up each part in the cards below.
Nodes and lines
title: StartNames the node. Every node needs one.
tags: introAny 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 noteA comment. Never shown.
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.
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.
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.
Operators
+ - * / %Maths.
% is the remainder.== !=Equal, not equal.
< > <= >=Less than, greater than, and so on.
and or xor notLogic. Or write
&&, ||, ^ and !.( )Work this part out first.
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.
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.
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 > 5In 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: onceThe node can run once.
when: alwaysThe node can always run.
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.
Commands
<<wait 2>>Pause for 2 seconds.
<<stop>>End the dialogue.
<<shake_camera>>Anything else goes to your game to handle.
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.
Tags and markup
Hello! #happyA tag your game can read.
Hello! #line:abc123A 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.