Is it harmful to create a massive "database" from a common event?

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
32
First Language
Not English
Primarily Uses
RMMV
Hey guys,

Im currently working on a system where im trying to make all interaction as global(common) as possible. For example: when you talk to a tree; the event that is that tree will give an ID, and will call a common event that ive used for storing different texts and options - and through that ID will find the text and options that belong to that tree event.
Basically it looks like this when the player talks to an interactable event:

Code:
◆Control Variables:#0073 interaction ID = 4
◆Common Event:#0017

The event will then direct whatever needs to happen to the common event ''database'':

Code:
◆If:interaction ID = 1
  ◆Text:None, Window, Bottom
  :    :im a chair
  ◆
:Else
  ◆If:interaction ID = 2
    ◆Text:None, Window, Bottom
    :    :im a clock
    ◆
  :Else
    ◆If:interaction ID = 3
      ◆Text:None, Window, Bottom
      :    :im a bush
      ◆
    :Else
      ◆If:interaction ID = 4
        ◆Text:None, Window, Bottom
        :    :hi im a tree
        ◆
      :Else
        ◆
      :End
      ◆
    :End
    ◆
  :End
  ◆
:End

My question is:
Will this take up alot of performance when it grows larger? I plan on having 100s of different interactable objects, and thus plan on making that "database" common event extremely large. And id like to know ahead of time if im handling this right. And if someone has any advice or tips to deal with this better, id love to hear that aswell!
 
Last edited:

Shaz

Keeper of the Nuts
Global Mod
Joined
Mar 2, 2012
Messages
46,006
Reaction score
16,821
First Language
English
Primarily Uses
RMMV
Yes, it will.

Each time, it will do the comparison, and if it fails, it will have to look through each individual line until it finds the corresponding Else command, repeating the process until it finds the correct response for that interaction id.

Even using labels and goto statements (if you had a script/plugin call that would let you use a variable as a label name) would require reading through the common event commands line by line until it found the correct label.

So the more options you have, the longer the lookup time could be. Some will be quick, if the interaction id is low, but some will take much longer, if the interaction id is high.

There are a few ways around this, and some of them include variations of what you have above. But a better way would be to create an array of all the responses, then pull the appropriate response into a variable based on the interaction ID, and use the variable in the text box. That would reduce your common event down to just a few lines. The array should be created as a script/plugin, because you don't want to put all the responses as a variable in your save file.
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
Personally I would use an object for this instead of an array. Reason for this is you can have named ids (and nested objects) making it easier to keep track of which lines of text go to which event. Using either an array or an object, I think you can avoid the use of a common event entirely and just call the data directly from the event in question.
Code:
//so this
var textArray = ['hello I am a tree', 'hello I am a box'];

//gets called like
textArray[0]
//=> 'hello I am a tree'

//Whereas an object would work like this
var textObject = {
    tree: {
        line1: 'hello I am a tree',
        line2: 'I don't move much'
    },
    box: {
        line1: 'hello I am a box',
        line2: 'Sorry Jack is out right now'
    }
};

//which can be called like so
textObject['tree']['line1']
//=> 'hello I am a tree'
 

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
32
First Language
Not English
Primarily Uses
RMMV
@Shaz @Sarlecc Hmm, those solution you guys brought me do seem really useful, especially the object thing. The only problem is that i barely have any idea how to make use of this. ive tried using it like this in an event script:
Code:
◆Script://Whereas an object would work like this
:      :var textObject = {
:      :    tree: {
:      :        line1: 'hello I am a tree',
:      :        line2: 'I don't move much'
:      :    }
:      :};
◆Script:textObject['tree']['line1']
in the hope that it would work. But, alas, I got an error - which came as no suprise, as i probably used it the wrong way. Also i noticed that you can barely add any code to a script call, so im assuming youre supposed to do all this in a plugin(not even sure on that)? And if i were to do this all in a plugin, how would i call on that plugin? Im an absolute noob when it comes to the ''scripting aspect'' of rpg maker MV, but i would really like to make use of this. Perhaps, would you care to give a slightly more "detailed" explanation on how I would get this to work? Thatd really help me out a ton I think.
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
Correct it would have to be done in a plugin in order to be the most use.
Here is an example of using it in a plugin *note this code is untested but I am fairly certain it should work (also you would put the following inside a file and save it with a .js extension and place it in your plugin folder):
Code:
//we will store the code functions in this variable named after you
var monkeyBiz = {};

//create an anonymous function to hide your text object from the global scope
(function ($) {

    //creation of the textObject
    var textObject = {
        tree: {
            line1: 'hello I am a tree',
            line2: 'I don't move much'
        },
        box: {
            line1: 'hello I am a box'
        }
    };
 
   //create a function to get the text from the textObject and store the function in monkeyBiz
   $.getText = function (event, line) {
        return textObject[event][line];
   };
})(monkeyBiz)
And in the event you just have to call it like so
Code:
Script: $gameMessage.add(monkeyBiz.getText('tree', 'line1'));
 

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
32
First Language
Not English
Primarily Uses
RMMV
Ok, so copy pasted this:
Code:
//we will store the code functions in this variable named after you
var monkeyBiz = {};

//create an anonymous function to hide your text object from the global scope
(function ($) {

    //creation of the textObject
    var textObject = {
        tree: {
            line1: 'hello I am a tree',
            line2: 'I don't move much'
        },
        box: {
            line1: 'hello I am a box'
        }
    };
 
   //create a function to get the text from the textObject and store the function in monkeyBiz
   $.getText = function (event, line) {
        return textObject[event][line];
   };
})(monkeyBiz)

In a .js file, called it Interaction_Dialogue, and put it in the plugin map, of my game. I also activated that plugin in the plugin manager, although im not sure if thats actually necessary. And i copy pasted this line
Code:
$gameMessage.add(monkeyBiz.getText('tree', 'line1'));
In an action event for testing; and that event contains nothing else.
Then when i talk to this event ingame, i get the error:
Code:
ReferenceError: monkeyBiz is not defined
Not sure what I did wrong here.
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
Hey,
Sorry for the late reply went camping.
Anyway the issue was my use of single quotation marks.
What happens is it is trying to look for another single quotation mark to finish line2: 'I don't move much'. Since it doesn't find one it results in an error which will keep the plugin off making monkeyBiz not defined.

Now to fix this you can do one of two things:
1. Wrap all the strings with double quotes instead of single quotes (reason I suggest doing it for all strings for this one is it keeps your code consistent).
Code:
//we will store the code functions in this variable named after you
var monkeyBiz = {};

//create an anonymous function to hide your text object from the global scope
(function ($) {

    //creation of the textObject
    var textObject = {
        tree: {
            line1: "hello I am a tree",
            line2: "I don't move much"
        },
        box: {
            line1: "hello I am a box"
        }
    };
 
   //create a function to get the text from the textObject and store the function in monkeyBiz
   $.getText = function (event, line) {
        return textObject[event][line];
   };
})(monkeyBiz)
2. Place a backslash in the string that is causing the error (which basically is telling javascript to ignore it).
Code:
//we will store the code functions in this variable named after you
var monkeyBiz = {};

//create an anonymous function to hide your text object from the global scope
(function ($) {

    //creation of the textObject
    var textObject = {
        tree: {
            line1: 'hello I am a tree',
            line2: 'I don\'t move much'
        },
        box: {
            line1: 'hello I am a box'
        }
    };
 
   //create a function to get the text from the textObject and store the function in monkeyBiz
   $.getText = function (event, line) {
        return textObject[event][line];
   };
})(monkeyBiz)
Anyway hope this helps. :)
 

Monkey BizNiz

Veteran
Veteran
Joined
Apr 22, 2017
Messages
229
Reaction score
32
First Language
Not English
Primarily Uses
RMMV
@Sarlecc Hey, I hoped you had a fun time camping!:) Also, it works now - and this information wont only prove useful for this situation, but also for many others to come, so thanks alot for your help!
 

Latest Threads

Latest Posts

Latest Profile Posts

GABposterwork.png

Working on a new poster.
I just posted the first devlog for The Hidden Art of Innkeeping: https://seaphoenix.itch.io/hiddenart!

BeachLogo.png
Might start playing some rpg maker games and uploading the games on youtube. Realistically they're not going to be for views. Just to give anyone some feedback on any games they're working on. So if you'd like me to play and review your game just reply them down here. And I'll upload them on Rpg4MGames.
Ah, so THIS is what it feels like to sleep till I naturally wake up, and not be woken up by an alarm or other unwanted stimuli... holy crap I feel like I can lift a house! XD (Or work on my game)

Forum statistics

Threads
131,614
Messages
1,221,602
Members
173,340
Latest member
Qed963
Top