Documentation menu

Build an advanced dialogue

Description: Revisit topics, change game state, grant an item, and offer conditional choices.

This tutorial builds on Build a dialogue. Charlie returns to Mira at the Wayfarer's Rest to ask about the inn and her missing ledger. Mira offers Charlie a key to the cellar passage after he agrees to help.

In this tutorial, you will learn to:

  • Use Jump nodes to return to a topic hub after an answer.
  • Make variable assignments in Instruction nodes to record conversation progress.
  • Call a game function to give the player an inventory item.
  • Set hide conditions to remove choices that don't apply or rewards already received.
  • Set disable conditions to show unavailable choices with an explanation.
  • Use a Hub to select a farewell based on the game state.

Tutorial project. Download the project. Open advanced_dialogue to begin with Mira, Charlie, and the function definition used below. advanced_dialogue_final contains the completed conversation.

The finished graph

Drag to pan, use the zoom buttons or scroll to zoom, and select Fit graph to see the whole graph.

Create the conversation state

Open Variables and add these three variables with type boolean. Set each default to false.

Variable When true
Inn_LearnedRumor Charlie has heard about the cellar passage
Inn_AcceptedJob Charlie has agreed to find Mira's ledger
Inn_ReceivedKey Charlie has the cellar key

The conversation flags in the Variables view

These variables belong to the project. Your quest or game code must respond to Inn_AcceptedJob by starting the quest or updating its objectives.

Review the item function

Open Functions and select addInventoryItem. The starting project includes this definition:

addInventoryItem(itemId: string, count: integer) -> void

Leave Pure off because the function adds an item to the inventory. The function returns void. The count parameter documents a default of 1, but this tutorial passes both arguments explicitly. If you are using your own project, add a definition with this signature first.

The addInventoryItem function signature and parameters

The definition describes a call. Your game implements it through the engine's function host. For this example, game code must recognize cellar_key as an inventory item ID and add the requested quantity to the player. It doesn't have to be a Narratyr entity. Narratyr doesn't provide an inventory system.

Build a topic hub

Open Quests & Dialogues, add a Dialogue, and name it MiraCellarKey. Set its title to The Cellar Key under Properties → Dialogue Info.

Drag from the entry node and add a Dialogue Line with Mira as its speaker:

Ask what you like. There is more to this inn than warm beds.

After Mira's greeting, add Branch on Conditions, which creates a Hub Node. Select it and open Properties in its node toolbar. Set Name to Topics. Give this Hub one output with no condition and connect it to another Dialogue Line.

Set the new Dialogue Line's speaker to Charlie, its short text to Choose a topic, and leave its spoken text blank. Add these four choices to Charlie's node:

  1. What's unusual about this inn?
  2. I'll look for your missing ledger.
  3. May I have the cellar key?
  4. That's all. Goodbye.

The Topics hub leading to Charlie's choice menu

The Hub forwards to the menu automatically. Charlie's Dialogue Node holds the player-facing choices. This keeps the entry to the topic menu separate from the lines the player selects. A Hub doesn't show its output branches as choices to the player.

Return after an exposition topic

From choice 1, add a Dialogue Line with Mira as its speaker:

The old cellar reaches under the mountain road. Its locked door is behind the kitchen.

After it, choose Execute Instruction. Set its name to Remember the rumor through the node's Properties popup and enter:

Inn_LearnedRumor := true

Add Jump to Node after the Instruction. Select the Jump, select Pick… in its toolbar, and then select the Topics Hub on the canvas.

The exposition branch returning through a Jump node

The Jump transfers execution to Topics without a return wire across the graph. The Hub then displays Charlie's menu again. Mira's greeting doesn't repeat because the Jump targets the Hub after it.

Accept the job

From choice 2, add a Mira Dialogue Line:

Find my ledger on the mountain road. Bring it back, and I will owe you a favor.

Add an Instruction named Accept the ledger job and enter:

Inn_AcceptedJob := true

Add a Jump after this Instruction and use Pick… to target Topics again.

An Instruction setting the flag that the quest or game can read

Both branches change state before returning to the menu. Accepting the job again sets the same value, so it doesn't grant another reward.

Give Charlie an item

From choice 3, add a Mira Dialogue Line:

Take the cellar key. If the road is blocked, the cellar passage may help you.

Add an Instruction named Give the key once. Enter both statements:

addInventoryItem("cellar_key", 1)
Inn_ReceivedKey := true

Resize the node from its lower-right handle so both statements are readable. Add a Jump after it and target Topics.

The item function call followed by the reward flag

At runtime, Narratyr calls your function host to give Charlie the item, then records the reward flag. The next section uses that flag to hide the key request after Charlie takes it.

Hide a choice until it makes sense

Select Charlie's menu node. Open the controls for choice 3 using its toolbox icon, then select the eye icon to set its Hide when condition:

not Inn_LearnedRumor or Inn_ReceivedKey

The key request's Hide when condition

A true hide condition removes a choice from the player's menu. Before Charlie hears the rumor, he doesn't know about the key. After he receives it, the same condition removes the request to prevent another reward.

Disable a choice until its requirement is met

In choice 3's controls, select the power icon and set Disable when to:

not Inn_AcceptedJob

Set Label when disabled to Accept the ledger job before asking for the key.

The key request's disable condition and alternate label

A true disable condition leaves the choice visible but unavailable. Charlie can learn about the key before agreeing to help Mira. The alternate label explains the requirement. Once he accepts the job, the request becomes available.

State Key request
Rumor not heard Hidden
Rumor heard, job not accepted Visible but disabled
Rumor heard, job accepted, key not received Available
Key received Hidden

Hide and disable conditions describe when to block the choice, so their meaning is the opposite of a Hub output condition, which describes when to follow a branch.

Branch to a state-dependent farewell

From choice 4, add a Branch on Conditions Hub named Ready for the road?. Give it two outputs. Connect output 1 to a Mira Dialogue Line with this text:

You have the key and a job to do. Good luck on the road, Charlie.

Set the condition on that output's connection to:

Inn_AcceptedJob and Inn_ReceivedKey

Connect output 2 to another Mira Dialogue Line:

Safe travels. If you change your mind, you know where to find me.

Leave output 2's connection condition empty. It's the fallback. Connect both farewell lines to the End Conversation node created with the graph.

A Hub choosing between two farewells from the conversation state

A Hub follows the first passing output in slot order. Put the conditional farewell first and the unconditional fallback second. If the fallback were first, it would always win. This decision happens automatically, while Charlie's topic menu waits for a player choice.

Try the conversation

Clear the selection, right-click the canvas, select Auto Arrange, and select Fit View to inspect the graph. Use the Full Graph tab above the image to compare connections and Jump targets.

The finished advanced dialogue graph

Start a simulation and try these routes from a fresh session:

Route Expected result
Say goodbye immediately Mira gives the ordinary farewell
Ask about the inn, then return The key request appears disabled
Accept the job, ask about the inn, request the key The item call runs once, and the key request becomes hidden
Say goodbye after receiving the key Mira gives the prepared farewell

The simulator marks hidden and disabled paths for inspection. A hidden path may still appear in its debugging list. Your game's player-facing menu should omit it. Use available paths when following these routes.

The simulator uses function mocks. Calling addInventoryItem in a simulation doesn't add an item to a real game inventory. Test your function-host implementation in the game to confirm that cellar_key is granted, and preserve the conversation flags in your game's save state if the reward should remain unavailable after loading.