I have two ways that I would like to load note-tags
1. When the database has finished loading. I would like to go to a particular database and just load all note-tags.
2. When the data is needed. This is just lazy-loading.
I have the second part figured out for the most part, but what would be the best way to load note-tags after database has finished loading?
I used to do method 2 back in the VX days. As a result, I found it can cause unfortunate amounts of lag at unoportune times if you have a lot of data to sift through, which was why I moved to loading notetag data while the game database is loading. It's also what MV does with its automatic notetag parser. In my opinion, while I'm playing games, I'd rather wait for some load time at the start than to get random spurts of lag spikes throughout gameplay. Even in an RPG, it can get pretty irritating (looking at you, Ar Tonelico 2).
As for how to load it for #1, I just have everything done at the DataManager.isDatabaseLoaded function.
You can always check to see if the data is available. For example, if $dataWeapons[1].attribute is something that would be added, you can go with
if ($dataWeapons[1].attribute === undefined) { $dataWeapons[1].attribute = 'defined';}As far as loading save data though, the $dataX information is always made at the start of any game instance, so there shouldn't be any issues collecting data unless the obj in question is independent of the base $data. When that happens, I just do the method I posted above and have the data update itself equal to the base object data to synch it together.
I was trying to figure out why this was here as well, until I read your post. So you're talking about MV? I'll move it over there then.
If it's a simple <tag: value> then it gets loaded automatically and you don't have to do anything at all.
If it's a more complicated structure (like nested), in previous makers you would add a call at the end of load_normal_database and process everything, but as MV loads asynchronously, the data will not be there at that point. You could either alias the method that builds the notetag data and know it will be called at the correct time, or you'd need to find out at what point the data load is complete (ie - what function finally triggers when DataManager says everything is loaded) and add your own processing there. I used the second method in the Lazy Tilesets plugin, but I'm not certain I got the right function. I think the first method might be cleaner, if you can manage it, and it has the added benefit of being run for maps as they are loaded, too.
In a recent plugin i'm writing, i extended Scene_Boot.prototype.terminate, since it's guaranteed to only run once, after all data has been loaded, and load all my notetags in there.
If you want to parse notetags for everything (like i do in my Note Files plugin), DataManager.extractMetadata is probably the right place. Since i also needed to async load my own files, i exported the original extractMetadata in a callback, that's executed once my data finishes loading.