Feature Tour

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, Tour.yarn, and every character starts a different node in it.

PLACEHOLDER — Screenshot needed
The Feature Tour in Play mode: the green player character in the first room, next to Capsley, with the row of rooms and their characters stretching away behind them, and Capsley’s first line in the dialogue box.

Running it

Open the FeatureTour scene in the Feature Tour sample’s folder and press Play.

ControlWhat it does
W, A, S, D or the arrow keysWalk.
SpaceTalk to the character you’re standing next to. A speaking indicator appears on a character when you’re close enough.
Space, or the button in the dialogue boxShow the whole line, or move on to the next one.
A left clickChoose an option.
Controls for the Feature Tour.

The dialogue doesn’t start by itself. Walk up to Capsley in the first room and press Space 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

FeatureTour
Dialogue System Dialogue RunnerIn Memory Variable Storage
Canvas CanvasCanvas ScalerGraphic Raycaster
Line Presenter Content Size FitterVertical Layout GroupCanvas GroupLine Presenter
Options Presenter Vertical Layout GroupContent Size FitterCanvas GroupOptions Presenter
Variables Canvas RendererTextMeshPro - Text (UI)
Line Advancer Line Advancer
Player Character ControllerSimple CharacterCharacter AppearanceMouth View
Camera Rig Simple Camera Follow
Main Camera CameraAudio Listener
Room 1 — Welcome
Room 1
Explanation Character Character ControllerSimple CharacterCharacter AppearanceMouth ViewDialogue Interactable
Room 2 — Nodes, Lines, Options, Jumps
Room 2
Explanation Character Character ControllerSimple CharacterCharacter AppearanceMouth ViewDialogue Interactable
NPC Nodes and Lines Character ControllerSimple CharacterCharacter AppearanceMouth ViewDialogue Interactable
NPC Options and Jumps Character ControllerSimple CharacterCharacter AppearanceMouth ViewDialogue Interactable
Part of the FeatureTour scene. Rooms 3 to 7 are left out, and are set up like Room 2.

There’s one Dialogue Runner for the whole building, on the Dialogue System prefab. Its Yarn Project is CharacterSample.yarnproject, which includes Tour.yarn, and its Presenters are the Dialogue System’s Line Presenter, Options Presenter and Line Advancer. See The Dialogue Runner.

Each character has a Dialogue Interactable, from the shared sample scripts. Its Dialogue setting is the Yarn Project and the node to start, picked from a dropdown, and its Dialogue Runner is the scene’s one Dialogue Runner. When you press Space next to a character, it calls StartDialogue() with that node name, and waits for the dialogue to finish. A character can’t be talked to while another conversation is running. If the node name is a node group, the speaking indicator only appears if something in the group can run. Character Appearance gives each character its own colours.

To find out which node a character runs, select the character in the Hierarchy and look at its Dialogue Interactable. Then find that node in Tour.yarn.

PLACEHOLDER — Screenshot needed
The Inspector for Sally, NPC Variables 2 in Room 4, with its Dialogue Interactable showing the Yarn Project and the node Room4_Variables_2.

Watching the variables

The Dialogue System’s In Memory Variable Storage has its Debug Text View set to the Variables text on the Canvas. Every frame, the Variable Storage writes the name, value and type of each variable it’s storing into that text. A variable shows up there once it has been set. As you talk to Sally, Ruby and Reginald, you can watch $player_spoke_to_sally, $player_meal and $player_gold change.

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.
    Reginald: I know you can afford to bribe me because you have enough gold.
    <<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.
  • Select a character, and change the node in its Dialogue Interactable to another one from the list, such as Room6_Functions_1. That character now says Beryl’s lines.
Next step Inline Events Markup that runs game code partway through a line, as the typewriter reaches it.