Pardon our dust while we move our docs here. The Godot (GDScript) docs are on this site, and the Yarn language, Unity, Godot (C#) and Unreal docs are still at docs.yarnspinner.dev.

The Feature Tour is a row of seven rooms. Each room has characters whose dialogue shows off part of the Yarn language: lines and options, jumps, detours, variables, enums, if statements, <<once>>, Commands, Functions, smart variables, line groups and node groups. A blue character called Capsley stands in every room and tells you what the room is about.

You walk the player character from room to room and talk to whoever you like. All the dialogue is in one Yarn Script, and every character starts a different node in it.

A green player character stands in the first room of a long building of low-walled rooms. Capsley, a blue character holding a coffee cup, stands to the left. More characters wait in the rooms further along. A dialogue box at the bottom shows Capsley saying Hi! Welcome to Yarn Spinner!
Capsley greeting the player in the first room.

Running it

Open samples/feature_tour/feature_tour.tscn and click Run Current Scene.

ControlWhat it does
W, A, S, D or the arrow keysWalk.
ETalk to the character you’re standing next to. A speaking indicator appears on a character when you’re close enough.
Space, Enter or a left clickMove on to the next line.
A left click, or the arrow keys and EnterChoose an option.
Controls for the Feature Tour.

The dialogue doesn’t start by itself. Walk up to Capsley in the first room and press E to begin.

What’s in each room

RoomCharactersWhat the dialogue showsYarn node
1CapsleyAn introduction to the tourCapsley_Welcome
2BobNodes and linesRoom2_Nodes_and_Lines
2BillOptions, and <<jump>> to another nodeRoom2_Options_and_Jumps_1
3Bruce<<detour>> to another node and backRoom3_Detours_1
4OgbertA variable used as the character’s name, set by an optionRoom4_Variables_1
4SallyNumber and boolean variablesRoom4_Variables_2
5Mary<<if>> and <<else>>Room5_IfStatements_1
5ThorAn option with a conditionRoom5_ConditionalOptions_1
5RubyAn enumRoom5_Enums_1
5Norb<<once>>Room5_Once_1
6DerekThe built-in <<wait>> CommandRoom6_Commands_1
6BerylThe built-in dice() and random_range() FunctionsRoom6_Functions_1
6ReginaldA smart variableRoom6_SmartVariables_1
7SvenA line groupRoom7_LineGroups_1
7Dr NodeA node groupRoom7_NodeGroups_1
The rooms, from the entrance to the far end.

Capsley’s node in each room is Capsley_Room2 to Capsley_Room7. For how each feature is written, see Writing Yarn Scripts.

Some characters react to what you did elsewhere. Mary and Thor say different things once you’ve talked to Sally, and Dr Node’s dialogue depends on the meal you chose with Ruby and on how much gold you have left after Reginald.

How it works

The scene

FeatureTourNode3D
RoomNode3D
Room2Node3D
WorldEnvironment
DirectionalLight3D
GroundStaticBody3D
CameraRigNode3D
Camera3D
YarnDialogueRunner
PlayerCharacterCharacterBody3D
CapsleyCharacterBody3D
DialogueInteractableNode3D
Capsley2CharacterBody3D
DialogueInteractableNode3D
BobCharacterBody3D
DialogueInteractableNode3D
CharacterAppearanceNode
UILayerCanvasLayer
LinePresenterControl
OptionsPresenterControl
HintLabel
DebugFollowMouseNode
Part of feature_tour.tscn. Room3 to Room7, Capsley3 to Capsley7 and most of the characters are left out. The other characters are set up like Bob.

There’s one Dialogue Runner for the whole building. Its Yarn Project is Tour.yarnproject, and its Presenters are the shared Line Presenter and Options Presenter from samples/shared/ui/. See The Dialogue Runner.

Each character has a child node with the shared dialogue_interactable.gd script. Its Node Name is the Yarn node to start, and its Dialogue Runner points at the scene’s one Dialogue Runner. When you press E next to a character, the script calls start_dialogue() with that node name, and waits for dialogue_completed. A character can’t be talked to while another conversation is running. If the node name is a node group, it can only be talked to if something in the group can run. CharacterAppearance gives each character its own colours.

Declaring the variables

All the variables in the tour are declared at the top of Capsley’s first node. Declarations aren’t run like other statements. They apply to the whole Yarn Project, so every node can use these variables, even if you never talk to Capsley.

<<declare $NPC_Variables_Name = "Ogbert">>
<<declare $player_gold = 10>>
<<declare $player_spoke_to_sally = false>>
<<enum Meal>>
  <<case None>>
  <<case Ramen>>
  <<case Pizza>>
  <<case MeatProduct>>
  <<case Sludge>>
<<endenum>>
<<declare $player_meal = Meal.None>>
<<declare $player_can_afford_bribe = $player_gold >= 6>>
Line 1 The name of the character in room 4. The option you pick there changes it, and their lines use it as the character name.
Line 2 Your gold. Sally tells you how much you have, and Reginald takes 6 of it.
Line 3 Set to true when you talk to Sally. Mary and Thor check it.
Lines 4–10 An enum of the meals Ruby offers.
Line 11 The meal you chose, which starts as None. Dr Node checks it.
Line 12 A smart variable. It’s true while you have at least 6 gold. See Smart Variables.
The start of the Capsley_Welcome node in Tour.yarn.

The smart variable

Reginald checks $player_can_afford_bribe. Nothing in the script sets it. Its value is worked out from $player_gold each time it’s read.

<<if $player_can_afford_bribe>>
    Reginald: Anyway. #line:Room6_SmartVariables_1_0400_Reginald 
    Reginald: I know you can afford to bribe me because you have enough gold. #line:Room6_SmartVariables_1_0500_Reginald 
    <<set $player_gold = $player_gold - 6>>
Part of Room6_SmartVariables_1, Reginald’s node.

You start with 10 gold, so the first time you talk to Reginald you can afford it, and he takes 6. That leaves 4, so $player_can_afford_bribe is now false. The next time, he says you can’t afford to bribe him.

Dr Node’s node group

Dr Node starts Room7_NodeGroups_1, which is a node group of five nodes with the same title. Each has when: headers that say when it can run. When the dialogue starts there, the Dialogue Runner picks one of the nodes that can run.

when: headersWhat Dr Node talks about
when: once and when: !visited("Room7_NodeGroups_1")How node groups work. Only shown once.
when: !$player_can_afford_bribeYou can’t afford a bribe.
when: $player_meal == .NoneYou haven’t got a meal.
when: $player_meal == .RamenYou have ramen.
when: alwaysThis node is a fallback.
The five nodes in the Room7_NodeGroups_1 node group.

The first time you talk to him, the node with once runs. Its two when: headers make it more specific than the nodes with one, so it wins even when another node, like the .None one, could run. After that, what he says depends on what you’ve done in rooms 5 and 6. The when: always node means there’s always something that can run, so you can talk to him as many times as you like. See Saliency and Storylets for how the Dialogue Runner picks.

Things to try

  • In Tour.yarn, change <<declare $player_gold = 10>> to <<declare $player_gold = 4>>. Sally tells you that you have 4 gold, Reginald says you can’t afford to bribe him, and after Dr Node’s first conversation, his when: !$player_can_afford_bribe node can be picked.
  • Add a fourth line to Sven’s line group in Room7_LineGroups_1, starting with => Sven:. Talk to him a few times to see each greeting.
Next step Commands and Functions Connecting Yarn Commands to camera, screen and inventory methods with a YarnBindingLoader.