0
101 Jul 25, 2003 at 20:54

Im trying to figure out how to store dialogs for my game, but cant find any useful way. I need to keep a quite complex dialog structure that not only have words, but also lua scripts, something like:

<NPC text>
<Hi>
if player.intelligence<10 then <Go hell>

Any suggestion?

#### 5 Replies

0
101 Jul 25, 2003 at 21:55

You would be better of using numbers for the events, as C’s string processing is a lot slower than just using a switch staement for numbers. You could use #defines if you still want the code to look readable. I’m unsure of the situation in C==, but numbers will still be way more efficient.

0
101 Jul 25, 2003 at 22:10

Well, of course, what I plan to return is and index representing the selected answer, not the whole answer if that is what you mean.

0
101 Aug 20, 2003 at 09:24

I use to use flat file databases for my website programming and i’ve picked up a few tricks from doing so - thus here are suggestion for how id go about storing dialog.

First you need a standard format of dialog of course.
example: [for an NPC name Torrus]

Torrus
dialogs {
#) Woah there cowboy! What might you be in such a hurry for?
#) I don't talk to the likes of you!
#) I'm looking for jobs to do!
#) Nothing lowlife - I didnt mean to talk to you anyways.
#) Help! My chicken has flown the coup!
#) Report back to me when you've completed the quest.
#) Fine then. What ever. Didn't want your help anyways.
#) Will you help me?
#) I don't think I'm ready for this quest yet.
#) You'r not done yet.
}
script <:{
if( npc_dont_like_player ) {
echo dialogs[2]
} else if( not_doing_my_quest ) {
echo dialogs[1]
if( give_option( dialogs[3], dialogs[4] ) ) {
echo dialogs[6]
} else {
echo dialogs[7]
}
} else if ( completed ) {
echo dialogs[11]
} else if ( uncompleted ) {
echo dialogs[12]
}
}:>


in short or templated form:
name
dialogs {
…dialogs here each new dialog started with #)
}
script <:{
script code here
}:>

Then you will need to create a function that can parse just this information
and a code that parses/runs your scripted code. You’ll noticed the curly brackets have been modified for the scripts area - this is to prevent miss parsing the code.

After you have that function working properly you “step up”.
create a file with several of those templates each seperated by say
<npc dialog seperator>

Which devides up the single file into sections. You have two options at this point. Either write a function that parses the single file and breaks up the dialogs for each npc into an array of User Defined Types for each dialog and search your array for a specific npc name that you are encountering..
OR..
You can write a seperate dos based program that compiles a list.dat from the npc dialogs file. List.dat will look something like this

Torrus 2
Leonardo 36
Jefferson 142


YOu can write a function that searches this file for the npc you are encountering - use the associated LINE index to grab the dialog template from your dialog file and send it through your dialog parsing function. This way will take up less memory as you dont store all the dialogs at once - All you store is the npc name and line index. But you will have to access the the npc file a lot.

I hope this helps more then confuses you. If you have any further questions dont hesitate to ask.

0
101 Aug 20, 2003 at 18:52

Thanks! That really clear things a lot for me.

0
101 Aug 20, 2003 at 19:19

nice written!! i’d like to see an article with working example about this! i’m not that much into string parsing and analizing, script execution and such..

well, i’ll have to dive into it anyways, i have to write a full shader-compiler! urgh:D