• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Advanced dialogue system

B

Beggar Studios

Guest
Hey everyone! I am creating a bit of a more advanced dialogue system in Gamemaker Studio 2 and I could use some pointers. This is how my dialogue system works now.

Every NPC has a parent that creates a list data structure called dialogue. When the player interacts with an npc a dialogue_update script is called. This script checks a conditions (if talked_to == 0 for example) and fills the data structure with the appropriate dialogue.

Code:
///scr_dialogue_update(npc)

var character = argument0;
var name = argument0.name;

switch(name){
    case "Seer":
        with(character){
            ds_list_clear(dialogue)
            ds_list_add(dialogue,

            "Oh, a new arrival have we? We'll I suppose you're plum out of luck! The Cartographer has locked the gates.",
            "We set up a temporary camp to the west. You'll find them quite the rag-tag bunch of misfits.",
            "We'd retrieve the keys from The Cartographer but no one has seem him for days.",
            "His tent is the green one to the east, but it seems to be deserted.",
            "This is quite disurbing indeed."

            );
        }
        break;
}
Then a dialogue object is created which actually handles the creation of the dialogue box and showing the text.

Now I want to make it a little bit more complicated. I want to dialogue of the npc to be dependant on a state. For example you could have welcome states, quest states or farwell states. But I want each of these states to have different dialogue everytime you talk to them. For example if you talk to the npc for the first time he is in the welcome state. You can talk to him three times before you exhaust his dialogue, but each of these three consist of multiple dialogue lines like in the above example. Then when you start a quest he has 5 dialogue trees.

My question is how do I properly store all the strings for the dialogue? I feel like this can get really complicated if I don't do this properly.

Could someone help me with this?
 

Hyomoto

Member
I'm working towards perhaps implementing a more robust dialogue system into my engine at some point so this is certainly something I've given some thought. However, the way it works right now is pretty simple. Basically all characters have a variable, 'dialogue'. To change what they say, this variable is all that needs to be updated. Their line of dialogue is generally set when they are created, such as the King here:
Code:
/// @desc Create
if quest_save_princess && !quest_built_bridge {
    dialogue    = "Thank you for saving the Princess. To aid your quest I ordered a bridge built to the continent. Go now, and make the ORBS shine again!!";
 
} else if quest_built_bridge {
    dialogue    = "The princess always worries about you.";
 
} else {
    dialogue    = "LIGHT WARRIORS__ Just as in Lukahn's prophecy.\nGarland has kidnapped the Princess. Please help her!!";
 
}
However, what if I want him to say something other than this? For example, once you've talked to him about building the bridge I don't want him to jump right to "The princess always worries about you." Like I said, this only happens on room start. It's possible to change what he says any time while the room is running as well, so I can do this:
Code:
/// @desc Window Open :: Build Bridge
if quest_save_princess && !quest_built_bridge {
    quest_built_bridge    = true;
 
    dialogue    = "Go on, your journey awaits you!";
 
}
Without getting into the technical details, essentially whenever a dialogue window is opened it will run a user event on the calling NPC where I can define custom actions. In this case, it checks if you are talking to him about the bridge being built, and if so sets that flag to true and then changes his dialogue. This system is not terribly complicated, but it is fairly robust since I can focus on the nuts and bolts of what should happen when you are interacting with an NPC. That's the core of the advice I would give here: you might be surprised at how simple you can make your system. If you aren't writing it for someone else to use it's probably possible to do what I've done here, write up a back end that handles the code I don't want to write over and over and then focus on a per-NPC execution. Anyways, maybe you find some of this useful. It's probably not as complex as what you are going for, but hopefully gives you some ideas.
 
B

Beggar Studios

Guest
That may work but I always try to circumvent long lists of if statements. For my project dialogue is always a ds_list. I can change the list dependant on the state variable but since I want it to change everytime I talk to an npc it has to be a list within a list. And it needs to be implemented easily for all npc's so they dialogue object needs to detect the lists and implement them
 
Top