Game Development Community

XML or database for storing conversation

by suddysud aka mrclean · in Torque Game Engine · 06/03/2006 (9:50 pm) · 13 replies

Hi this is a simple question. probably not engine related.

I am going to have Tons of text in my game since it's a game with much dialogue.
I was thinking about where and how best to store all that data.
I thought XML files would be interesting vs. a standard relational database.

I'm curious to hear thoughts on the benefits of XML over a standard relational database.

I was thinking that the heirarcial structure of the XML database would fit very well for conversations where people get a choice of responses to choose - which in turn trigger more conversation.

Example:
What can I help you with?
A. Forget out about it
B. XYZ
C. ABC
D. DCE

When the player chooses one of those responses it inturn triggers more conversation.

And is there an XML library around that would be real good for getting in and out of an XML file using C++ ?

Thanks

#1
06/03/2006 (11:33 pm)
My favorite xml lib is tinyxml. It's easy to use and easy to drop into a project. I used it for a school project last semester and I was really pleased with it. www.grinninglizard.com/tinyxml/ is the main tinyxml site.

Using an xml file to store conversations sounds like a great idea, simply because you would be able to edit it with a simple text editor, making it fairly trivial to make changes to a character's lines.
#3
06/04/2006 (2:51 pm)
Okay this is a real simple xml question


I am setting up the xml file.
Is this a legitimate way to get data from the node.
<statement>
     here is a conversation statement
     <responses-option>a. here is a clever answer
                     <statement>here is a follow up statement.
                                         <responses-option>  </responses-option>
                                         <responses-option>   </responses-option>
                     </statement> 
     </responses-option>
     <responses-option>b. another clever answer
     </responses-option>
</statement>

does that look like a pretty legitimate way to put conversation in an xml file and get the statement out of there even though the data and the next nodes are sort of in the same place
#4
06/04/2006 (5:28 pm)
I'd do the following:

<statement>
      <question>
            <text>What time is it?</text>
            <questionID>29</questionID>
      </question>
      <answer>
            <text>a.  It is nine in the evening.</text>
            <followupID>31</followupID>
      </answer>
      <answer>
            <text>b.  It is five in the mornng.</text>
            <followupID></followupID>
      </answer>
</statement>

Each statmenet refers to a single question and a set of answers. Each quesiton has a question id that you can use to find followup questions. If it's empty, there is no followup.

dish
#5
06/04/2006 (10:39 pm)
You can probably simplify it by using attributes. I'd probably do something like this:

<character name="Bill">
    <statement id="30" sound="whattime.wav">
        What time is it?
        <response followup="31">
            It's 4:30!
        </response>
        <response followup="32">
            Off hand I can't say.
        </response>
        <response followup="33">
            [Ignite laser sword]
        </response>
    </statement>

    ... more statements go here ...

</character>

You probably want the ability to jump around in conversation arbitrarily, so organizing it in a straight hierarchichal manner might be not the best way. For instance, two responses might eventually lead to the same place in the conversation, but one might be in a more roundabout way. I believe with the straight hierarchy, you might have situations where you need multiple instances of the same statement.
#6
06/05/2006 (3:35 am)
The attributes versus tags thing is an old and ongoing argument. The general "rule" is to have attributes for things only relevant to the program and tags for things the user will see. Just my tuppenceworth, and I'm certaily not going to get into a discussion about it as this thread would turn into a mega-thread :-)
#7
06/05/2006 (7:28 am)
@Dave that sounds like a good general rule
and i like drews xml using that rule for the follow up id

@All
However I was just curious to know what kind of call to "Character/statement" would selectively pull out the text after statement and not the response nodes as well or if it is possible. Could someone give an example xml call that would pull out just the text "What time is it?"

<character name="Bill">    
        <statement id="30" sound="whattime.wav">        What time is it?       
                      <response followup="31">            It's 4:30!        </response>
                      <response followup="32">            Off hand I can't say.        </response>        
                      <response followup="33">            [Ignite laser sword]        </response>
       </statement>  
</character>
#8
06/05/2006 (9:08 am)
If you're using tinyxml, "What time is it?" will be a TiXmlText node which is a child of the "statement" TiXmlElement.

Assuming you have the "statement" element:

(untested)
TiXmlElement* e = statement->FirstChildElement();
while(e)
{
    TiXmlText* text = e->ToText();
    if(text)
    {
         const char* theText = text->Value();  // this is how you get the value
    }
    e = e->NextSiblingElement();
}
#9
06/06/2006 (8:15 am)
Do you all have any thoughts about encrypting and decrypting the xml file as needed? So that players can't open it up change it and pass it around
#10
06/06/2006 (8:21 am)
Could use the encrypted zip resource and include you xml files in it along with the resource files?

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9896
#11
06/06/2006 (8:27 am)
I'd suggest encrypting fields within the xml file, and not the entire xml file itself.
#12
06/06/2006 (10:29 pm)
If you encrypt the text, I would suggest writing a dialogue editor program, so that you don't have to run every line of text through some kind of translator program before putting it in the xml file.

Personally, however, I'd just leave it open and let the user modify it if he wants. A lot of gamers consider the ability to mod a game a perk. Unless, of course, your game is going to be rated by the ESRB, hehe.
#13
06/06/2006 (11:06 pm)
You don't need a translator program, you simply base64 encode it which you can easily find code samples for in good ol google.