Dealing with data parsing and dynamic objects

It is common practice in RM scripting to take advantage of note-tags and event comments as a means of accepting user input, or providing some way to enter this data in the script (as part of the configuration).

An issue I've noticed with several scripts is that they do not support dynamically created objects, for example if you create an event and put it on the map, or you capture an enemy and add it to the party as dynamically created actor.

The problem is due to the way the data is parsed: they assume all data is created on load-time.

For example, many scripts I have seen load object notetags such:

module DataManager alias 😮ld_load_db :load_database def load_database old_load_db $data_weapons.each do |weapon| weapon.load_my_notetags end endendThis method is called only once when the game starts up, so if you were using scripts that created new objects (and not simply re-using existing database objects via referencing), the new objects will not load any note-tags or comments.What are some ways to address this issue?

Some may not see this as an issue at all, but if your script does not support dynamic objects, then you automatically have something to write in your list of compatibility issues.

One solution is to use lazy loading, which initializes the data if necessary whenever it is accessed. This is an effective way to handle the problem because it doesn't matter how many different note-tag loading methods are available, they will always be called if the data has not been initialized.

Problems with this include initialization time: if it takes too long to load the data, players will notice the delay.

If you are working with external database systems, it may be better to query for all data at once rather than making separate queries one at a time.

Another solution is to define a new data parsing interface that provides a `load_notetags` or `load_comments` method.

class RPG::BaseItem # this would be defined in all classes with a note-box. def load_notetags endendOther scripts would alias the load_notetags method and call their own note-tag loading logic.Then in your scripts, you would make sure that anytime an object is created, you call the load_notetags method so that all of the required note-tags are loaded.

This requires more coordination on ALL scripters' parts, and would require all existing scripts to be changed, which is impractical.
I read all my database notes on loading the database - it's more efficient than reading them every time an object is accessed for a particular task. But I do it by calling a read_notes method of the class (which could be called at any other time in the game, though I don't). Really, people should not be changing the $data_ contents, as they're persistent across games unless you also start including them in the save files.


I do the same for getting behaviour values from event comments - it's done as part of loading the events, so there's no delay while the map's visible, where any script is reading through 100 lines of event code looking for particular comments.


You've just got to use the best way of reading notetags within the context of your own game.
i usually use lazy method you mentioned...  i read them ONLY when needed and i don't notice any delay either. since mostly not running at the same time. to make it faster we can init it for the first time accessed only. save it to a variable. (formar method 😀 )

ex:

def myvar   @myvar = yournotetagsgrabbingcodehere if !@myvar   return @myvarendit will grab the notes if myvar is still not exist or false.

if it already grabbed before then it will return the saved variable.

so it will be harder to "RUN" at the "SAME" time scenario. since some might already initialized before. so it won't be noticeable i guess. (who knows 😀 )

edit: by adding attr_accessor to @myvar above we can change it's value later too. (for something that can be changed ingame).

above case won't have problem with new object. but might have issues with changing existing object which already initialized.
You've just got to use the best way of reading notetags within the context of your own game.
Definitely. If you're not going to use any dynamic content in your game, it wouldn't make sense to implement functionality to handle dynamic content.


This would apply more for people that are writing scripts for others as opposed to their own projects, since there are more compatibility issues to consider when anyone could be using your script.

Original thread: https://forums.rpgmakerweb.com/threads/dealing-with-data-parsing-and-dynamic-objects.18821/