How do dialog trees actually work? What is connected to what and how to move between lines of speech when a sub-conversation ends?
If you have any examples of a basic dialog tree in C#, please post them.
The name "dialogue tree" is a bit misleading - they usually are simple directed graphs, not just trees. The basic data structure of such graphs usually consists of some kind of "data" for the nodes, which represent the points we are at in the conversation, and links from them to other nodes, which represent what is being said and done by the participants and optionally have conditions on them to limit their visibility or scripts to perform various additional actions. Usually one of the nodes is the default starting node (typical labels for that are "ROOT", "START" and "GREETING"), and nodes which have no valid links leading from them end the conversation.
In most cases, the graph is represented in-memory as a list of
Instead of having complex rules and conditions on links, you can instead get by with a simple "valid" boolean variable, which can be then changed from either the scripts of other conversation links (including the default one from the starting node) or by outside mechanisms. In general, this approach is simpler but only suitable for games with very few such conversations, since it moves the logic of "When is this response possible?" away from the response data itself.
Note that the structure I describe here is slightly different from Byte56's in that the nodes don't need to have any dialogue lines; the links can have them all. In the most basic variant, this translates to the following structure.
Dialog trees are created with a directed graph structure.
The graph is traversed based on the dialog decisions the player makes. The dialog options provided to the user come from the edges that define the paths to other dialog nodes.
Directed graphs are a basic data structure. They can easily be implemented and you'll likely want to implement it yourself. Since you'll want to tailor the graph to your dialog needs.
Some of the nodes may need to have special conditions met in order to show up. For example, the player would require a skill in speech above X. Or the player needs to have completed mission Z before they can progress down one branch of dialog. Or they need to ask something 4 times before the NPC will discuss it with them. These features will be custom to your game. But are worth mentioning when you're implementing the node and edge traversal. Of course it's always best to start with the simplest form and build up from there.
I've built a simple dialogtree system: http://iki.fi/sol/d3/ the "engine" itself is currently plain c, but the data produced by the editor is pretty simple to use in any language. The tool outputs XML, JSON and a custom binary format.
The main concept is pretty simple:
Each node (which I call "card", as with the above analogue) of the dialog consists of question text and zero or more answers. Each of the answers leads to another card.
There's also a tag system where certain answers are shown to the user only if a tag is set (or a tag is not set). Entering a card sets (or unsets) specified tags.
This is pretty much everything one needs to do just about any kind of dialog in a game. The "question text" can be plain text, or it can be a script to drive animation or whatnot.
You can use TreeSharp and behaviour trees to model a dialogue system. TreeSharp is a library that provides a simple behaviour tree implementation. IA bots for wow are done with this, so it's mature... :)
My implementation has nodes that let choose between answers, and each answer can be joined to othe dialogue or an action, or a sequence of actions, or a node that lets going to another dialog... or what yo want...
I have used brainiac editor to make it visually... but at the end it produces c# code based on treesharp...