0
\$\begingroup\$

I'm trying to figure out a good way to implement dialogs (that is, talks, not UI's). My thoughts so far:

  • I see a dialog as a tree of sentences (or better, a forest), so I think that XML is a good choice.
  • There would be a XML file for each NPC. And more files for generic NPC's. Example: Peter.xml, Linda.xml, Citizen.xml, Soldier.xml, etc.
  • These files would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<dialog npcName="skeleton">
<ops>
	<q>Hi, how are you?</q>
	<a>Oh, thank you! It's been so long since I was last asked about that...</a>
	<a>Well, so and so. And you?</a>
	<ops>
		<q>Oh, I'm fine. But you look starving. I'll fetch some food for you.</q>
		<a questActivate="eggToSkeleton">Don't worry. In fact, I have no stomach,
        so the groceries would fall to the ground if I tried to eat. For example:
        if I ate an egg, it would break for sure.</a>
		<q>I was wandering how a skeleton can talk. And how can be 'so and so'.</q>
		<a>What? Haven't you ever heard about undead?</a>
		<q objectCondition="egg, inInventory" objectAction="egg, destroy"
           questComplete="eggToSkeleton">I have an egg just here. Let's try to
          see what happens.</q>
		<a>*The skeleton eats... well, it puts the egg into its mouth. When its
          bony fingers release the egg, it begins to roll down and finally
          crashes to the ground, leaving an orange splash among the green 
          blades of grass.*</a>
		<a>Just as I told you. But... thanks.</a>
		<farewell mode="polite"/>
	<ops>
	<q>Begone, monster! You are an unnatural being!</q>
	<a>Yes, I know. But it is not my fault, and I can do nothing about that. I 
      can't even commit suicide!</a>
	<farewell mode="rude"/>
</ops>
</dialog>

I have no experience with XML and I haven't found sample codes for this purpose. Am I on the right path?

\$\endgroup\$
  • \$\begingroup\$ Are you having an actual problem? If so, what is it? Questions asking whether or not some approach is a good one (or "on the right track") are generally to opinion or discussion oriented for the main site, though you could try the Game Development Chat. \$\endgroup\$ – user1430 Jan 11 '15 at 17:30
1
\$\begingroup\$

Overall, yes.

The answer nodes should contain the sub-questions rather than the <ops> section.

The objectAction and questActivate should be sub-nodes of answers rather than attributes as one answer could have more than one action.

Conditions should also be sub-nodes of questions or answers as there could be multiple conditions and can become complex.

<q text="simple question">
  <a text="yes">
     <if object="egg" count="1"/> <!-- answer only avail. if egg==1 -->
     <action object="egg" add="-1"/>
     <action quest="the egg" add="-1"/>
     <action object="gold" add="500"/>
     <q text="Good job">
       <a text="Bye."/>
     </q>
  </a>
  <a>
     <text style="angry">NO! A VERY LONG <i>COMPLEX</i> TEXT</text>
     <q text="some other question">
        ....
     </q>
  </a>
</q>

Or something along those lines.

\$\endgroup\$
  • \$\begingroup\$ I see. Putting the text as an attribute or as a text subnode allows answer nodes to have subnodes. Thanks. \$\endgroup\$ – user2425 Jan 11 '15 at 11:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.