Creating a Dynamic Dialog System

wiffle88

Villager
Member
Joined
Nov 3, 2016
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
Hi all!

I believe this is the right place to post this question? I'm not entirely sure. I am using MV as that's just what I own.

The context:

I was attempting to duplicate a dynamic dialog system I saw in a game I backed on Kickstarter, World of Anterra. Their dialog system is designed to have the player enter a word when talking to an NPC, then the NPC will check a database and if there's a response for that word, display the response. This encourages the player to learn about the world on their own instead of just being explictly told things.

The way the devs describe it is that there are global dialog databases, regional dialog databases, etc, all the way down to personal NPC dialog databases. The system checks the smallest possible database first to see there's a response for the player entry, and then continually checks larger databases until it finds a response. There are several responses possible for each entry. Once the system determines how the NPC responds, that specific response is then seeded to that specific NPC so that the player can't get all possible responses by inputting the same entry with one NPC.

Example.png

Question 1:

I created a basic version of this system using events that worked quite well. It used common events, name input processing, and variables to determine the correct response for an NPC event. However, this only allowed for one response per entry. I got a friend involved who is more proficient in coding than I, and she managed to figure out how to store multiple responses and have the NPC event recall one response at random and display it. Which is super cool! Here's the eventing and script calls used for this.

Contents.png
Not shown: the "regional database" runs and then, using conditional branches, if there's not a matching response in the "regional" section it runs the "global" section which is copied and pasted underneath.

My question is, is this the most effecient way to go about this? Doing it the way I showed above requires 3 control variables to be used for each response, just for the dialog system. This would quickly add up to several hundred if not thousands of control variables.
('Apples', 'Oranges', and 'Grapes' were used as test responses because we didn't want to type out whole lines until we got it to work.)

Question 2:

Now that we're able to have an NPC event pick a stored response at random and display it, is there a way we could "seed" that specific response to the NPC? This would be to prevent the player from getting say, all possible responses to a question or topic by inputting the same word to one NPC.

We were trying to think through it but I'm not amazing with coding and have passable knowledge of the engine, and my friend is good at coding but doesn't know the game engine very well.

We were attempting to use a Self Control Switch in the NPC event, but that would require a switch for every response, right? And that would quickly get out of hand. Anyway, we couldn't figure out a way to do this because the NPC event is only setting a Regional Dialog Variable and then running a common event that starts the dialog system process. And I can't get the common event to talk to the NPC event.

Pics for system example:
NPC Event runs this:
Contents_2.png
Contents_3.png
Contents_4.png

Thank you all! If I need to be more clear, let me know! Happy game making! :smile:
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
5,765
Reaction score
5,562
First Language
English
Primarily Uses
RMMZ
Rather than storing your responses in game variables, I would store your databases in json files or in an actual SQL database and use node's SQL functions to retrieve data (which would prevent you from doing a web deployment of your game since that doesn't support node functions).

Then I would repurpose the variable approach to "seed" the response by storing the one retrieved in a variable, and have a conditional branch to check whether it's set. However, to save on game variables for this purpose, I would have the variable be an array with a multi-key index where the key is an array consisting of the map ID and event ID of the NPC, and the value is a key-value object where the key is the topic and the value is their response to it. That can then be retrieved as needed thereafter. Or do it like self switches where the key is [map ID, event ID, topic] and the value is the response.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,929
Reaction score
4,768
First Language
English
Primarily Uses
RMMV
My question is, is this the most effecient way to go about this? Doing it the way I showed above requires 3 control variables to be used for each response, just for the dialog system. This would quickly add up to several hundred if not thousands of control variables.
No. Aside from @Trihan's suggestion about using a proper database, I would suggest making use of a plugin that can display the results of a JavaScript eval in the text window. (Eliaquim has one, VisuStella message might be able to)

That way you're not needing to use any game variables in the process at all and you can just display the output of the database query directly.
 

LordOfPotatos

Veteran
Veteran
Joined
Oct 9, 2015
Messages
188
Reaction score
171
First Language
english
Primarily Uses
I'm pretty sure I've seen plugins that let you set up variables like self switches, which would let you use self variables in each NPC event instead of using normal variables.

You could seed a response by setting up a conditional branch with the random response variable == 0, and inside it setting the random response to something.
that way the random response is randomized only when you talk to that event for the first time.

I'm trying to find that plugin :/

Edit: it's YEP_SelfSwVar. from Yanfly.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
5,765
Reaction score
5,562
First Language
English
Primarily Uses
RMMZ
I'm pretty sure I've seen plugins that let you set up variables like self switches, which would let you use self variables in each NPC event instead of using normal variables.

You could seed a response by setting up a conditional branch with the random response variable == 0, and inside it setting the random response to something.
that way the random response is randomized only when you talk to that event for the first time.

I'm trying to find that plugin :/

Edit: it's YEP_SelfSwVar. from Yanfly.
Yeah, that's basically a plugin version of what I suggested.
 

wiffle88

Villager
Member
Joined
Nov 3, 2016
Messages
5
Reaction score
1
First Language
English
Primarily Uses
RMMV
I'm pretty sure I've seen plugins that let you set up variables like self switches, which would let you use self variables in each NPC event instead of using normal variables.

You could seed a response by setting up a conditional branch with the random response variable == 0, and inside it setting the random response to something.
that way the random response is randomized only when you talk to that event for the first time.

I'm trying to find that plugin :/

Edit: it's YEP_SelfSwVar. from Yanfly.
If it was designed this way, the events and scripting would need to be run inside of the NPC event, not as a common event, correct? But in theory, once you have one event done, you could just copy/paste the event and change the sprite.

To make a change to it, you could just use Yanfly's Event Copier plugin to make sure any changes get updated across every duplicate event.

EDIT: Actually, Yanfly's Event Copier copies everything, including the sprite. Unless I'm mistaken, I don't think there's a way to turn that part off. So I'd need to make several different versions? Or am I over/underthinking this.

I'm not sure how to double quote here so, Trihan said:
Rather than storing your responses in game variables, I would store your databases in json files or in an actual SQL database and use node's SQL functions to retrieve data (which would prevent you from doing a web deployment of your game since that doesn't support node functions).

Then I would repurpose the variable approach to "seed" the response by storing the one retrieved in a variable, and have a conditional branch to check whether it's set. However, to save on game variables for this purpose, I would have the variable be an array with a multi-key index where the key is an array consisting of the map ID and event ID of the NPC, and the value is a key-value object where the key is the topic and the value is their response to it. That can then be retrieved as needed thereafter. Or do it like self switches where the key is [map ID, event ID, topic] and the value is the response.
I'll see if my coding friend understands what this means. As I'm guessing that this might be a cleaner way, in the long-run, to do this? (As opposed to doing with with plugins.)
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
6,929
Reaction score
4,768
First Language
English
Primarily Uses
RMMV
I'm not sure how to double quote here
Just do whatever you did to quote the first time. If you press Reply on another post, it'll post the quote wherever your cursor is.

You can also use the +Quote buttons ahead of time to quote multiple posts and arrange which order they get pasted in. Or you can highlight a portion of text with your mouse and the Reply button for just that bit will show up.

this might be a cleaner way, in the long-run, to do this? (As opposed to doing with with plugins.)
Ehn? Plugins, generally, have nothing to do with it. I personally think Trihan's centralized method is a bit cleaner than using self-variables/switches on individual events that you have to keep track of someplace. But either way could absolutely work.
 

LordOfPotatos

Veteran
Veteran
Joined
Oct 9, 2015
Messages
188
Reaction score
171
First Language
english
Primarily Uses
If it was designed this way, the events and scripting would need to be run inside of the NPC event, not as a common event, correct? But in theory, once you have one event done, you could just copy/paste the event and change the sprite.
I think you could make each NPC event have it's own self variables, then make said NPC event set the global variables that the common event uses to equal it's own self variables before calling the common event.

that way the common event can reference the NPC's self variables, and you can use a common event. if I'm understanding this right.

also, I would warn against building systems you can't clearly understand like using an SQL database without knowledge of SQL.

I've heard ugly code you understand is better than clean code you aren't sure of as long as it works.

but that's just my opinion.
 

Latest Threads

Latest Posts

Latest Profile Posts

Hi sweethearts! :kaoluv: Check out my review of @EntangledPear's totally oldskool The Stuff Fairy Tales Are Made Of!
When you spend all day at work distracted by things you want to work on or try in your project and then by the time you get home, you are too mentally tired to concentrate so you just browse the forum instead and think of more things you won’t get to work on for a while.
Time to write some enemy behaviors, here's the stream link for those interested.

Call of duty 1&2 had an interesting cheat prevention method. Between levels the game unloads and reloads the engine dll. If you ever employ this method, make sure to include at least an md5 hash check. Otherwise I can just edit that dll and implant cheats into it.
Hi-Fi Rush is one of the coolest games I've seen in a while. I don't have a way to play it so I watched a friend and wow... I really wish I had a powerful enough computer for it.

Forum statistics

Threads
128,276
Messages
1,193,252
Members
168,731
Latest member
lolcode
Top