Jump to content
  • Advertisement
Sign in to follow this  

NPC Conversation

This topic is 4827 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been thinking about how best to implement conversations with NPCs in my game....should I represent them as a tree structure, as there are multiple branches the conversation could take? Should I store conversation in text files and then load it into a tree in my game? Any articles or ideas/help would be appreciated. Cheers

Share this post


Link to post
Share on other sites
Advertisement
Hi,

I'm new to the forums, and game programming. I intend to start coding again soon. An old axiom in programming is, Seperate data from processing.
If the data is static, put it in a file. Do not mix code and data.
Code should be used only to process the data stored elsewhere.

Input the data.
Process the data.
Output the data.


Input from the user (a File Request)
Process the request open the file and read the relevant string.
Output the string to the user.

Think of every NPC as a File.

I haven't seen what gaming programmers do, I've just bought a few books on the subject, and intend to start my own project, but standard coding is as above.

Share this post


Link to post
Share on other sites
You pretty much answered your own question, hehe. I think a XML tree-design would work the best and it is what I did until I removed dialogue choices from my game. It would work something like this:

<Dialogue>

<Conversation>

<Line id="1">
<Choice>Yes</Choice>
<Content>Hello there, would you like to hear about rings?</Content>
<Choice id="2">Yes</Choice>
<Choice id="3">No</Choice>
</Line>

<Line id="2">
<Choice>No</Choice>
<Content>So you DO want to hear about them...cool</Content>
</Line>

<Line id="3">
<Choice>No</Choice>
<Content>Then leave me alone!!</Content>
</Line>

</Conversation>

</Dialogue>

Then you can parse that in using an XML parser..I suggest TinyXML :)

Hope that helps.

Share this post


Link to post
Share on other sites
Thanks for the suggestion, but I've never used xml and am using c# (so tinyxml won't work?). Is there a tree structure built into xml then, and can I use system.xml to load it somehow?

Share this post


Link to post
Share on other sites
Depends how complicated you want things to be. Using a tree like structure works fine but might be a bit static - there are always the same conversations.

I've implemented an event driven system so that each conversation topic or even each conversation element can be triggered by an event - if you visit the dark castle then NPCs might start talking about it. Or if you kill the king then no one wants to talk to you any more. That kind of thing.

It is still possible to build conversation trees by having dialogue options triggering events further down the tree.

Allows for richer dialogue in my view, but is harder to implement and it can be really nasty to debug conversations.

Jon.

Share this post


Link to post
Share on other sites
I would advice using XML too. Actually any text parsing system could be used but XML is standardized and has some good ready made parsers. If you are going to have a lot of conversations and you think the text will take up a lot of hard disk space you could write a binary converter later on and make your program handle both file formats, but I guess you would'nt gain that much since most of the conversation data is flowing text anyway.

Here is an introduction to XML and how to think of it.
http://www.gamedev.net/reference/programming/features/xml/

When making complex conversations I find it esier to think of them as flowcharts with floating nodes connected by alternatives rather than the strict hierarchy of a tree. Often it is useful to draw a diagram of the full conversation in order to prevent dead ends and infinite loops.

Best of luck jameswren.

Also, welcome to the forums jcullen24. Hope you'll find being here useful.[smile]

Share this post


Link to post
Share on other sites
Thank you, Yes I have found these forums invaluable! I have already picked up 2 books that were suggested in the resource section. The one I'm currently reading is Game Programming All in One 2nd editon by Jonathan S. Harbour.

I'm delighted that the game dev community has grown, and there are so many tools out there! I tried my hand about 10 years ago with Allegro. I always wished there was a printed reference on the library instead of getting information piecemeal off message boards.

These message boards have been a great source of information, and inspiration.

Thank you, and hopefully I will be able to contribute. I fear my knowledge is ten years out of date though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!