Commands

You can send instructions to your game through commands. Commands look like this:

Yarn
title: Start
---
<<wait 2>>
<<setsprite ShipName happy>>
<<fade_out 1.5>>
===
Three commands.
sequenceDiagram
  participant ys as Yarn Spinner
  participant game as Your game
  Note over ys: #lt;#lt;wait 2#gt;#gt;<br>Built in: waits for 2 seconds
  ys->>game: #lt;#lt;setsprite ShipName happy#gt;#gt;
  game-->>ys: Finished
  ys->>game: #lt;#lt;fade_out 1.5#gt;#gt;
  game-->>ys: Finished
What happens when this script runs. wait is built in, so Yarn Spinner handles it itself. The other two commands are sent to your game, and the dialogue carries on once each one has finished.

Commands are sent to your game’s Dialogue Runner, like lines and options are. Commands are not shown to the player directly; instead, they’re used for things like stage directions.

Yarn Spinner comes with some built-in commands, and you can also define your own custom commands that make your game do what you need to.

Built-in Commands

There are two built-in commands in Yarn Spinner: wait, and stop.

wait

The wait command pauses the dialogue for a specified number of seconds, and then resumes. You can use integers (whole numbers), or decimals.

Yarn
title: Start
---
// Wait for 2 seconds
<<wait 2>>

// Wait for half a second
<<wait 0.5>>
===
The wait command.

stop

The stop command immediately ends the dialogue, as though the game had reached the end of a node. Use this if you need to leave a conversation in the middle of an if statement, or a shortcut option.

Yarn
title: Start
---
// Leave the dialogue now
<<stop>>

// Leave the dialogue if we don't have enough money
<<if $money < 50>>
    Shopkeeper: You can't afford my pies!
    <<stop>>
<<endif>>
===
The stop command.

Making Your Own Commands

You can create your own commands, so that your scripts can send directions to your game. For more information on how to create them in Unity games, see Creating Commands and Functions, in the Yarn Spinner for Unity section of the documentation, and equivalents for other engines.

We recommend that you only move into the documentation for your game engine after learning the fundamentals of Yarn Spinner Scripting.