Since finishing Fluster I’ve had some time to think about different game ideas. One discussion with my friend Eddie started me thinking about dialogue trees. For his upcoming game Psychedelic Farmer he needs to create dialogues between the different characters and would also like the dialogue to be different depending on the items the player is carrying. I haven’t found the solution to this problem yet but I have started thinking about it, I thought I’d share my thoughts and get some feedback from you guys.
I approached this problem thinking about a dialogue as a tree. Each node in the tree should represent one statement in the dialogue. When there is more than one response possible then that should represent a choice for the player. Here’s how it might look:
Dialogue as a Tree
<dialogue>
<statement text="Welcome to my store." />
<statement text="Hey there, what can I do for you?">
<response text="I'd like to buy something." />
<response text="I'd like to sell something." />
</statement>
</dialogue>
There are a couple of problems with that, I think. First off it doesn’t really
meet all of the Eddie’s requirements so we’ll need to extend it. Worse, it
isn’t clear how this will drive the game, somehow we need to alert the game
when a given node is reached. To that end I’ve added ID’s to important nodes. Presumably the dialogue engine can trigger an onNode event when the player selects an important node (e.g. he selects the “Buy stuff” option).
Dialogue Tree with IDs on Important Nodes
<dialogue>
<statement text="Welcome to my store." />
<statement text="Hey there, what can I do for you?">
<response text="I'd like to buy something." />
<statement text="What would you like to buy?">
<response id="buy-weapon" text="I'd like to buy a weapon." />
<response id="buy-item" text="I'd like to buy an item." />
</statement>
<response id="sell-something" text="I'd like to sell something." />
</statement>
</dialogue>
Now, what about having multiple dialogues in a file? And what about having dialogues be context sensitive? My first sense for this problem is to create a mechanism to index into the XML for the desired attributes. For instance, you might want to find the dialogue between Eddie and the store keeper:
Dialogue Trees with Character Indexing
<dialogues>
<characters>
<character name="Alex" description="Swash buckling pirate-ninja!" />
<character name="Eddie" description="Possibly drug using farmer." />
<character name="Bob" description="Bob of Bob's Dry Goods fame." />
</characters>
<dialogue primary="Bob" secondary="Eddie">
<statement text="Welcome to my store." />
<statement text="Hey there, what can I do for you?">
<response text="I'd like to buy something." />
<statement text="What would you like to buy?">
<response id="buy-weapon" text="I'd like to buy a weapon." />
<response id="buy-item" text="I'd like to buy an item." />
</statement>
<response id="sell-something" text="I'd like to sell something." />
</statement>
</dialogue>
<dialogue primary="Alex" secondary="Eddie">
<statement text="Nice pineapple, I'm going to take it!" />
</dialogue>
</dialogues>
I’ve declared a list of characters at the top and then added primary and secondary attributes to each dialogue. The primary attribute designates the person being spoken to, e.g. Bob the store owner, while the secondary attribute designates the listener — usually the player. Naturally, I would extend this idea to work for items, too. Perhaps a reasonable constraint would be to have an optional single item as an index for a dialogue which would make it easy/fast to grab the right dialogue tree given two characters and an item.
So this is where I am right now. So far I think this could work for some cases, such as an exchange between the main character and some NPC. Still it’s clear it won’t work if we try to have a conversation between more than two characters. For instance, if a member of your party wants to interject some advice mid-conversation. With all of that said, how do you manage the dialogue tree in your game?
If you have any ideas and would like to hack around this problem with me, feel free to edit my gist on the subject.
Hello, my name is Alex Schearer. I grew up in New York and currently live in Seattle.
5 Comments
Hi, maybe you can have a look at Neverwinter Nights, goold old CRPG from Bioware. There are some developer resources here: http://nwn.bioware.com/developers/ There should be a description for the Dialog-file format (gff files).
Thanks, this looks really useful, definitely going to have to dig in!
Yep, I was going to suggest looking at neverwinter nights as well. It has a very powerful dialogue engine. I’m not sure how they implemented it, but it’ll give you ideas for nice features – i.e. jumping between portions of the tree depending on selected options, tying scripted events/triggers to responses, etc. If your game is anything more than text based, you’ll probably end up wanting to define things like animations to play or camera movements, within the tree as well.
i’ve found this editor for nwn dialog system:
http://flamewind.com/programs.html
I developed my own dialog tree system for the Telepath RPG series, and structurally, it’s similar to what you have, though I approach certain things differently. I use two different functions: (1) a conversation function which calls the appropriate dialog and reply text depending on two variables (the conversationID, which is usually just the name of the person you’re talking to; and the conversationBranch, which is simply a number that differentiates the different–you guessed it–branches of the dialog tree); and (2) a reply function, called when you click a reply button, that changes the conversationBranch (and possibly other things as well) depending on the current conversationID and conversationBranch, as well as which reply button you clicked (via a third variable, the replyID). The reply function then calls the conversation function to update the dialog and replies.
One Trackback
[...] http://www.anotherearlymorning.com/2009/05/whats-in-a-dialogue-tree/ [...]