Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Implementing a dialog system in a game?

Author
Message
Yodaman Jer
User Banned
Posted: 16th Mar 2016 14:28
So for my game I am going to need a dialog system. I have a few ideas and I think the simplest one might be this but I am wondering if anyone else has any other ideas!

The best idea I can come up with is that all of the dialog is stored in a file, which will also use tags to "attach" the dialog to specific characters in the game. Each character will be based off of a UDT which will have variables that control the NPC's current mood, their name, and the dialog.

Depending on their mood, the dialog will will either be happy, sad, or angry. For quest characters they will just have "neutral".

So, for example I might be able to do this...


Instead of hard-coding the text though, I would definitely use a file system to store the dialog. I'm thinking something like this:


Then I could parse through the file, and according to the mood set the dialog accordingly. I haven't really used parsing before though so I would have to research that but I'm sure it's not difficult.

The current dialog that would load as the player interacts with the NPC would get assigned to one text object that would reset itself once the player has finished talking to them. I would have a function that loads the dialog once the player presses the appropriate key to interact with the NPC.

I feel like parsing through a file on the fly may slow the game down a bit, however, so I'm wondering what I could do to better optimize it?


Slowly compiling code, one byte at a time.
Follow meh blague for more zany thoughts and possibly offensive programming!
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 16th Mar 2016 15:18
Seems like a solid idea you've got there. I've been thinking about this as well. About reading/parsing during active sessions, if the conversation (text) files become to big, you could always split those up (for example on "mood") so when "mood = happy" the other files regarding other moods could be ignored.

Hope my two cents helps!
Regards Sph!nx
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 17th Mar 2016 03:33
I did it like that:

1. Create a file that contain all sentences in your level, you can use a xml parser or something more simple

joe_dialogue_street_1 = 'Hey kids...'
joe_dialogue_street_2 = '... You know what time it is?'
joe_dialogue_backdoor_1 = 'It`s dangerous to go alone, take this!'

2. Save everything in a dialogue array

3. Write a command that can return the dialogue string by the name: sentence$=GetDialogue("joe_dialogue_street_1")
4. Now you need a dialogue creator, its enough to have a seperate textfile containing following:

dialogue1 = 'joe_dialogue_street_1,joe_dialogue_street_2'
dialogue2 = 'joe_dialogue_backdoor_1'

5. Parse them in, like your sentences into a seperate array

6. If you activate your dialogue, a counter has to jump inside the current dialogue triggering all seperate sentences.

7. Combine this with a trigger system for graphics/ Sound.

Cheers, Jack

[/url]
Yodaman Jer
User Banned
Posted: 17th Mar 2016 14:42
I think I figured out a way to simplify this.

Instead of having the dialog stored in a file, I will find a way to store the properties of NPCs in my map editor. I've done it before with other map editors so I know it's not difficult. I would use Edit Boxes to actually type the dialog the NPC would say, and then just assign the edit box text to the dialog variable of that particular NPC object.

Basically, code could look like this:


I think that really simplifies the process, and that way dialog is also saved to each specific map - it will literally be part of the data in the map, meaning the player also won't be able to (as easily) hack into it and change it.

What do you guys think? Would that approach be good?
Slowly compiling code, one byte at a time.
Follow meh blague for more zany thoughts and possibly offensive programming!
Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 17th Mar 2016 21:09
That is a good idea if you don't need multi-language support

[/url]
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 18th Mar 2016 03:17

Embedding the dialog creation it the editor seems like a natural solution. You could get past the language issue by making the level/world saver export the dialog text separately into to an indexable heap. So character/game object just stores a list of string references, which would be the line number into the heap (a text file). Then 3rd parties should be able to make translations once the level/game is done. If you’re worried about the data protection, then you could encrypt the final language files.. Although tokenizing the text would serve much the same purpose.

You could also use a custom markup for things like names, places that might need to be inserted into text at runtime. I generally use square bracketed tags so they’re they’ve got a known first and last character, so finding them in a string is trivial. But it doesn’t really matter.


PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Yodaman Jer
User Banned
Posted: 19th Mar 2016 19:41
I'll be honest, I never even thought about multi-language support. I don't think my game will make it that far

I will hammer out a test for this dialog system in the next few days and post my findings here. I may try a few different techniques and see which one works the best!
Slowly compiling code, one byte at a time.
Follow meh blague for more zany thoughts and possibly offensive programming!

Login to post a reply

Server time is: 2024-09-29 13:22:58
Your offset time is: 2024-09-29 13:22:58