Dialogue System
A dialogue system is a web of lines. Each line moves on to the next or offers the player answers, and an answer can depend on what the game remembers, change it, or appear only once. The big risk is a soft lock, a dead end where every answer is hidden, so check for one before release.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Dialogue System" to my game.
What it should do: Dialogue lets the player talk to the world, and what they say and do changes what comes next.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> line
line: Says a line
ended: Ended
stuck: Stuck
choices: Waits for answer
line --> line: next line
line --> choices: answers on offer
line --> ended: nothing follows
line --> stuck: every answer hidden
choices --> line: answer leads to a line
choices --> choices: answer, more answers
choices --> ended: answer ends the talk
choices --> stuck: every answer hidden
ended --> [*]
stuck --> [*]
```
Use these starting values:
- historyLimit: 50
Watch out for these common mistakes:
- Every answer is hidden: Tell your AI to give every point with answers one that has no conditions, and to check that when the conversation loads.
- An answer offered once is the only way out: Tell your AI that an answer offered once does not count as the way out, and to check for that when the conversation loads.
- A line nobody can reach: Tell your AI to walk the conversation from the start when it loads and report what it did not reach.
- A link to a line that is gone: Tell your AI to check every link when the conversation loads. If a broken link is ever followed, the game should stop with one clear message that names the missing line, whether the player picked an answer or just moved on.
- A conversation that never ends: Tell your AI to check when the conversation loads that, from every line, links and answers with no conditions lead to an end.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
What it does
Dialogue lets the player talk to the world, and what they say and do changes what comes next.
How it runs, as a diagram
Everything it can be in, and what moves it on. Your AI builds from exactly this.
How it runs, as a diagram
- Says a line → Says a line: next line
- Says a line → Waits for answer: answers on offer
- Says a line → Ended: nothing follows
- Says a line → Stuck: every answer hidden
- Waits for answer → Says a line: answer leads to a line
- Waits for answer → Waits for answer: answer, more answers
- Waits for answer → Ended: answer ends the talk
- Waits for answer → Stuck: every answer hidden
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| historyLimit | 50 | How many past lines the game keeps. More lets players look further back. |
What usually goes wrong
Every answer is hidden
If all the answers at a point have conditions, the player can be left with nothing to pick and no way out. This is a soft lock. It depends on what the game remembers, so it is easy to miss when you test.
Fix: Tell your AI to give every point with answers one that has no conditions, and to check that when the conversation loads.
An answer offered once is the only way out
An answer offered once that loops back leaves the point empty on the second visit.
Fix: Tell your AI that an answer offered once does not count as the way out, and to check for that when the conversation loads.
A line nobody can reach
Writers add a line and forget to link it, and it never appears.
Fix: Tell your AI to walk the conversation from the start when it loads and report what it did not reach.
A link to a line that is gone
After an edit, an answer leads to a line that no longer exists, and the game fails at the moment the player picks it.
Fix: Tell your AI to check every link when the conversation loads. If a broken link is ever followed, the game should stop with one clear message that names the missing line, whether the player picked an answer or just moved on.
A conversation that never ends
Every answer leads on, but they all lead back, so the player always has something to pick and can never leave. Nothing looks broken, which makes this easy to miss.
Fix: Tell your AI to check when the conversation loads that, from every line, links and answers with no conditions lead to an end.
How to check it works
- A conversation. you start it: it is at the opening line, and that line is in the list of past lines.
- An answer that needs something the game remembers. you reach it without that, then with it: the answer is hidden, then on offer.
- An answer that something the game remembers rules out. the game remembers that thing: the answer is hidden.
- A hidden answer and one that does not exist. you ask your AI to show you what happens if either is picked: nothing changes.
- An answer that makes the game remember something. you pick it: the game remembers it and the conversation moves to where the answer leads.
- An answer offered once that you have already picked. you come back to that point: it is no longer on offer.
- A point with answers. you try to move on without picking one: nothing changes.
- A finished conversation. you try any action: nothing changes.
- A limit of 2 and a run of 3 lines. the conversation runs: the last 2 lines are kept.
- Broken conversations: a soft lock, a bad link, a line with no way in and a missing start. you ask your AI to show you what the conversation check says: each problem is reported, and a conversation with no mistakes reports none.
- A conversation where every answer leads back. It loads: The check reports that it can never end.
- A conversation nobody checked, with a link to a line that is gone. The player follows it, by moving on or by picking an answer: The game stops with the same clear message both ways.
Common questions
how do you make a dialogue system
Store dialogue as data: each line has its text and either the next line or a list of answers. A small part of the game keeps track of where the conversation is and what it remembers, and offers only the answers whose conditions are met.
what do i tell my ai to add a dialogue system
Paste this: Add a dialogue system stored as data, where answers can depend on what the game remembers, and check when it loads that every link exists, every line can be reached, every set of answers has one with no conditions, and every line has a way to the end.
what is a soft lock in dialogue
A point where every answer is hidden, so the player can neither go on nor leave. Give every point with answers one without conditions, and check that when the conversation loads.
how do i remember what the player said
Save a short named note when an answer is picked, and let later answers need it or rule it out. Keep the names plain, so writers can read them.
Where it comes from
Earliest example we could find: Deadline (Marc Blank, Infocom) (1982). A text mystery in which the player has to question suspects. The player types a character's name followed by a question or demand, or uses ASK and TELL about a topic. Jimmy Maher describes earlier games' conversation as passwords or a plain TALK TO command. This is the oldest game located here with a described conversation model; ELIZA (1966) is older but is not a game.
- 1966 ELIZA (Joseph Weizenbaum), paper in Communications of the ACM 9(1): Precursor, not a game. A program that spots key words in typed input and builds a reply from rules attached to them. It is included as a precursor because game-writing histories, including Brent Ellison's, start with it. [ELIZA: A Computer Program For the Study of Natural Language Communication Between Man And Machine (Joseph Weizenbaum, CACM, January 1966)][Defining Dialogue Systems (Brent Ellison, Gamasutra/Game Developer, 2008)]
- 1982 Deadline (Marc Blank, Infocom): A text mystery in which the player has to question suspects. The player types a character's name followed by a question or demand, or uses ASK and TELL about a topic. Jimmy Maher describes earlier games' conversation as passwords or a plain TALK TO command. This is the oldest game located here with a described conversation model; ELIZA (1966) is older but is not a game. [Playing Deadline, Part 1 (Jimmy Maher, The Digital Antiquarian, 2012)][Playing Deadline, Part 4 (Jimmy Maher, The Digital Antiquarian, 2012)][Deadline (Jimmy Maher, The Digital Antiquarian, 2012)]
- 1983 Murder on the Zinderneuf (Jon Freeman and Paul Reiche III, Free Fall Associates; published by Electronic Arts): The manual has the player choose an approach to a suspect from a list that differs by detective, then choose whom to ask about. Suspects react differently to the role and approach. The player picks a manner and a topic, not lines of text. This is the oldest menu-based conversation located here. Reiche later reused the idea for Starflight. [Atari Game Manual: Murder On The Zinderneuf, full text (Internet Archive)][Free Fall, Part 2: Murder on the Zinderneuf (Jimmy Maher, The Digital Antiquarian, 2013)][Starflight (Jimmy Maher, The Digital Antiquarian, 2014)]
- 1989 Indiana Jones and the Last Crusade: The Graphic Adventure (Noah Falstein, Ron Gilbert, David Fox; Lucasfilm Games): The manual tells the player to choose what Indy says from phrases listed at the bottom of the screen, and warns that a poor choice can cause trouble. This is the earliest game located here where a primary source documents picking literal lines. Alexander Freed also lists Space Rogue (1989) as an example of a conversation tree, without describing it. [Indiana Jones and the Last Crusade: The Graphic Adventure, manual (Lucasfilm Games, 1989; scan at mocagh.org)][Branching Conversation Systems and the Working Writer, Part 1: Introduction (Alexander Freed, Game Developer, 2014)]
- 2005 Facade (Michael Mateas and Andrew Stern): A research work and interactive drama in which the player types free dialogue at any time. Its authors state the aim of moving past branching narrative. It marks a line of work that treats conversation as an AI problem instead of an authored tree. [Facade, authors' submission statement (Electronic Literature Collection, volume 2)][Defining Dialogue Systems (Brent Ellison, Gamasutra/Game Developer, 2008)]
- 2012 AI-driven Dynamic Dialog through Fuzzy Pattern Matching (Elan Ruskin, Valve, GDC 2012): A developer talk on matching facts about the world against a database of lines, so characters choose what to say without a hand-written script for each case. Used in Left 4 Dead and other Valve games. Here the player does not pick lines at all, so it shows dialogue selection as a rules system. [AI-driven Dynamic Dialog through Fuzzy Pattern Matching. Empower Your Writers! (GDC Vault)][GDC 2012 Talk on Dynamic Dialogue (Emily Short, 2012)]
What was checked
- 17 tests pass on the reference code.
- The state diagram was checked against the code, at the default values and at every listed low and high value.
Your AI gets the code
Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it