• Create Account

# Datastructures for story and dialog

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

9 replies to this topic

### #1lole  Members   -  Reputation: 116

Like
0Likes
Like

Posted 21 June 2012 - 09:30 AM

Hello,

I'm working on an Amiga Games in Blitz Basic. Inspiration is from Moonstone, Diablo 3, and Monkey Island 1, but it's basically a shoot-em-up/side-scroller. It will be based on an open map, like Moonstone, where routes between places (e.g. planets or space stations) are shorter shoot-em-up stages. In each place you can buy / sell, talk to characters, etc.

Upon this, I'd like to have a story. The question is how this should be represented in the game. I have a number of types (structs) to start with, for example, Character, Dialogue and Quest. I am also thinking of making an editor where you can create new characters, and above all dialogues.

Does anyone have experience with something similar? I'd like to avoid FSM, just think it leads to cluttered code. Would also like to avoid a lot of if-statements and switch statements for each characer, like "if quest1 done then say else say blah blah".

One solution would be to implement a small scripting language that takes care of decisions for the characters, and which can be loaded dynamically (the behavior of a character can then be loaded and replaced when a certain quest is completed).

Ideas, anyone?

### #2M6dEEp  Members   -  Reputation: 904

Like
0Likes
Like

Posted 22 June 2012 - 12:31 AM

I would personally end up with some kind of tree structure that can easily be represented in xml. You can implement some kind of serialization for this dialog tree and then you could make all of your dialog bs offline (or maybe even make a dialog creation tool if you felt extra cool). You can add some extra metadata to the dialog to define the types of characters that use it, one for merchants, one for warriors etc.

The cool thing is that you could also implement some kind of dialog engine on top of it that would unlock certain options as you progressed through the story. You can rank each dialog option with a flag. This flag could be just a simple data type like an int that denotes how far along in the story you are. I think that if you follow this idea you could also add tons of really awesome features like random dialog options appearing.

### #3lole  Members   -  Reputation: 116

Like
0Likes
Like

Posted 23 June 2012 - 06:37 AM

I would personally end up with some kind of tree structure that can easily be represented in xml. You can implement some kind of serialization for this dialog tree and then you could make all of your dialog bs offline (or maybe even make a dialog creation tool if you felt extra cool). You can add some extra metadata to the dialog to define the types of characters that use it, one for merchants, one for warriors etc.

The cool thing is that you could also implement some kind of dialog engine on top of it that would unlock certain options as you progressed through the story. You can rank each dialog option with a flag. This flag could be just a simple data type like an int that denotes how far along in the story you are. I think that if you follow this idea you could also add tons of really awesome features like random dialog options appearing.

I think that is a darn good advice. A tree structure in this case will mean a recursive data structure, something like (pseudo C):

struct dialog {
string text; // The actual dialog line
int quest_id; // Which quest does this dialog belongs to
int character_id; // Who is saying this
... // More flags
}

Since I'm programming in BlitzBASIC on Amiga, I will have to do the XML-parser my self. Perhaps it will be easier to actually do that dialog creation tool instead.

### #4bollµ  Members   -  Reputation: 358

Like
0Likes
Like

Posted 23 June 2012 - 09:30 AM

as far as I've seen, XML is overkill for almost everything you need, though in this situation, it *may* be justified. I personally feel a list name-value pairs is enough for dialog, because XML takes pretty long to parse (storing level data in XML isn't pretty either if your level gets pretty big).

If you want to use XML, make sure you follow the KISS principle.

If you're looking for XML parsers, I suggest you first read up on them. There are 2 types of XML parsers- DOM parsers and SAX parsers. I'm pretty sure that you're familiar with DOM. In this model, the parser creates the DOM(document object model) which can then be queried for relevant data. This has an upfront cost but (strictly IMO) allows easier manipulation.

SAX parsers on the other hand require you to register callbacks with them when they hit different XML Elements. These callbacks are then called with the required data. I haven't used a SAX parser myself because the DOM parser was in my comfort zone. you may go for either one, and I'm pretty sure there's someone with more experience than me who can tell you the pros and cons of this

I'm not really sure if any XML parsers are available for BlitzBasic. you'll have to research that yourself.

Hope this helps
~Siddu

a WIP 2d game engine: https://code.google.com/p/modulusengine/

English is not my first language, so do feel free to correct me

### #5antiHUMANDesigns  Members   -  Reputation: 58

Like
1Likes
Like

Posted 23 June 2012 - 08:39 PM

I would personally end up with some kind of tree structure that can easily be represented in xml. You can implement some kind of serialization for this dialog tree and then you could make all of your dialog bs offline (or maybe even make a dialog creation tool if you felt extra cool). You can add some extra metadata to the dialog to define the types of characters that use it, one for merchants, one for warriors etc.

The cool thing is that you could also implement some kind of dialog engine on top of it that would unlock certain options as you progressed through the story. You can rank each dialog option with a flag. This flag could be just a simple data type like an int that denotes how far along in the story you are. I think that if you follow this idea you could also add tons of really awesome features like random dialog options appearing.

I think that is a darn good advice. A tree structure in this case will mean a recursive data structure, something like (pseudo C):

struct dialog {
string text; // The actual dialog line
int quest_id; // Which quest does this dialog belongs to
int character_id; // Who is saying this
... // More flags
}

Since I'm programming in BlitzBASIC on Amiga, I will have to do the XML-parser my self. Perhaps it will be easier to actually do that dialog creation tool instead.

Whoop, careful with the infinite recursion, there. "struct Dialogue" with member array of type Dialogue, so that each object spawns another 10 objects that spawn another 10 objects...

You're probably aware of it, I just felt like pointing it out for the lols.

Btw, awesome that you're programming on an Amiga. I used to program AMOS when I was a kid. Have you tried that? It's like QBasic, but with more powerful graphics stuff.

Edited by antiHUMANDesigns, 23 June 2012 - 08:41 PM.

### #6M6dEEp  Members   -  Reputation: 904

Like
1Likes
Like

Posted 24 June 2012 - 03:36 AM

as far as I've seen, XML is overkill for almost everything you need, though in this situation, it *may* be justified. I personally feel a list name-value pairs is enough for dialog, because XML takes pretty long to parse (storing level data in XML isn't pretty either if your level gets pretty big).

If you want to use XML, make sure you follow the KISS principle.

Strongly emphasize the KISS principle and XML. I believe that XML is a great intermediate format to use for editors etc. You can easily parse it and then create a binary file that is both much smaller and faster to read in.
<dialogs >
<dialog characterId="2" questId="1">
<characterLines>
<text>What do you want</text>
could put tons of text elements here and randomly pick from them to add a little variety (what do you want, hi nice to see you etc)
</characterLines>
</dialog>
More dialogs..
</dialogs>


Then you just serialize this to binary from your custom tool ("compile" it) and you are good to go. I think that the recursion stuff needs to be approached carefully but could be done. Another interesting thing is that you can procedurally pick from many dialog lines so even though the answers are the same you can simulate the characters having moods etc.

EDIT:

Oh and I forgot to mention, if you can work out the serialization to and from binary, you don't have to write that pesky XML parser, you could just use C#'s already excellent XML parsing mechanisms and forgo all of the headache.

Edited by M6dEEp, 24 June 2012 - 03:37 AM.

### #7darksheikh  Members   -  Reputation: 102

Like
0Likes
Like

Posted 25 June 2012 - 04:06 AM

I always had a problem writing xml parser
Live Television: http://www.hdlivestreams.com
Online Shopping: http://www.shoppynow.com

### #8lole  Members   -  Reputation: 116

Like
0Likes
Like

Posted 01 July 2012 - 12:29 PM

Hello!

Nice with some answers! I've tried on a number of forums without any result.

After some quick research I've decided that an XML-parser is too big for this project, for now atleast. So I'm just gonna implement some light weight configuration language which can read text into my data types. Something like so:

new dialog
id = d1
quest = 1
text = bla bla
end
new dialog
id = d2
quest = 1
text = but no
anwsers =
end


Also, if you want to check out my project, this is the webpage: www.tonesoftales.com/blitz/

Bye!

### #9lole  Members   -  Reputation: 116

Like
0Likes
Like

Posted 01 July 2012 - 12:32 PM

I would personally end up with some kind of tree structure that can easily be represented in xml. You can implement some kind of serialization for this dialog tree and then you could make all of your dialog bs offline (or maybe even make a dialog creation tool if you felt extra cool). You can add some extra metadata to the dialog to define the types of characters that use it, one for merchants, one for warriors etc.

The cool thing is that you could also implement some kind of dialog engine on top of it that would unlock certain options as you progressed through the story. You can rank each dialog option with a flag. This flag could be just a simple data type like an int that denotes how far along in the story you are. I think that if you follow this idea you could also add tons of really awesome features like random dialog options appearing.

I think that is a darn good advice. A tree structure in this case will mean a recursive data structure, something like (pseudo C):

struct dialog {
string text; // The actual dialog line
int quest_id; // Which quest does this dialog belongs to
int character_id; // Who is saying this
... // More flags
}

Since I'm programming in BlitzBASIC on Amiga, I will have to do the XML-parser my self. Perhaps it will be easier to actually do that dialog creation tool instead.

Whoop, careful with the infinite recursion, there. "struct Dialogue" with member array of type Dialogue, so that each object spawns another 10 objects that spawn another 10 objects...

You're probably aware of it, I just felt like pointing it out for the lols.

Btw, awesome that you're programming on an Amiga. I used to program AMOS when I was a kid. Have you tried that? It's like QBasic, but with more powerful graphics stuff.

Hello!

It's not really infinite recursion, since the array really is pointers to dialogs, not dialogs itself. Hm, perhaps this is not appearent from my code...

Amiga is indeed a lot of awesomeness. I hope I will have time to finish this project. I tried Amos but switched to BlitzBasic. Don't remember why. Don't know about QBasic?

Edited by lole, 01 July 2012 - 12:41 PM.

### #10lole  Members   -  Reputation: 116

Like
0Likes
Like

Posted 01 July 2012 - 12:40 PM

as far as I've seen, XML is overkill for almost everything you need, though in this situation, it *may* be justified. I personally feel a list name-value pairs is enough for dialog, because XML takes pretty long to parse (storing level data in XML isn't pretty either if your level gets pretty big).

If you want to use XML, make sure you follow the KISS principle.

Strongly emphasize the KISS principle and XML. I believe that XML is a great intermediate format to use for editors etc. You can easily parse it and then create a binary file that is both much smaller and faster to read in.
<dialogs >
<dialog characterId="2" questId="1">
<characterLines>
<text>What do you want</text>
could put tons of text elements here and randomly pick from them to add a little variety (what do you want, hi nice to see you etc)
</characterLines>
</dialog>
More dialogs..
</dialogs>


Then you just serialize this to binary from your custom tool ("compile" it) and you are good to go. I think that the recursion stuff needs to be approached carefully but could be done. Another interesting thing is that you can procedurally pick from many dialog lines so even though the answers are the same you can simulate the characters having moods etc.

EDIT:

Oh and I forgot to mention, if you can work out the serialization to and from binary, you don't have to write that pesky XML parser, you could just use C#'s already excellent XML parsing mechanisms and forgo all of the headache.

Again, I'm not using C#, but a basic dialect on Amiga called BlitzBASIC. Thanks for the tip, though.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS