Editing notes in code

Greetings all,

I want to make a plugin that edits object notes via code but I don't know my way around the RPGM engine very well. I know where the notes themselves are stored but not when and where the game reads them in to make use of them. Can someone tell me what function(s) I need to look at?
Well notetags are stored in the data files which are then converted from string format to object format upon starting/loading a new game. This is all done in the DataManager class in the onLoad function. The onLoad function uses the extractMetaData() function which uses regex to convert the string to an object. If you need a way to get the meta information you simply use the the $dataClass.meta object to access it. Swapping $dataClass with whichever you want to extract from.

PHP:
var myMeta = $dataActor.meta['tagname']

Code:
///For convenience, you can make a function to get the meta object value.
      getMetaData(obj, tag) {
        if (obj === 'undefined') {
          return 'undefined'
        }
        var meta = obj.meta
        var match = Object.keys(meta).filter(function (key) {
        key.toLowerCase() === tag.toLowerCase()
        })
        return typeof meta[match] === 'string' ? meta[match].trim() : meta[match]
      }
Then to get the data simply use
PHP:
var myMeta = getMetaData($dataMap, ''notint')
@DGM
That Idea has been asked and discussed several times ago, and in most cases the people asking for this don't understand that this is a bad idea that won't work in most cases anyway.

The notes are usually loaded at new game and then stored internally. Changing the notebox during game will not force the engine to reload the notes, so most plugins will ignore any changes you make that way. So even if you write that plugin to change the notes, a lot of plugins will simply ignore the successfull changes of the noteboxes and use their own pre-loaded data for it.

Additionally, redirecting the meta function will only work for those plugins that use the meta structure - a lot of plugins have their own parser for their notetags, because they need the data in a different format - which is another reason why you didn't find a general answer, because a lot of plugins use their own functions for this.

The only reliable method to change the behaviour of any script that is controlled by notetags is to analyse that specific plugin, check where and how it stores data after it was loaded from the notetag and then change that plugindata directly.
However, that needs a different method depending on the plugin, it can't be generalized.
Thanks for the warning, but that's not a problem. I don't want to change the notes mid-game and I'm not concerned with how any particular script uses them. I just want to alter them once at the beginning before they're used at all. So it sounds like what you're saying will work to my advantage.
Will it? I'm not really convinced about that or the utility of your idea. Because if you change them before they're loaded and do nothing after the game starts, it would be easier to make those changes permanent by using the editor where you place them anyway.

However, if you want to do that your best bet would be to rewrite or redirect the json datafiles of the game, before the default code acesses them.
You can open the json files in any text editor to see their structure and look to where they store the noteboxes (use a text editor, not a json editor for that). And since they have fixed names, you can look through the core files to detect where they're opened and redirect that to the functions of your plugin.
This seems to be one of those cases where we might be able to advise you better if you tell us what it is you're trying to do rather than how you're trying to do it.
Because if you change them before they're loaded and do nothing after the game starts, it would be easier to make those changes permanent by using the editor where you place them anyway.

It's not easier if you want to make the same change to every object of a given type.

Are you familiar with Yanfly's Base Troop Events plugin? Same idea, only for modifying things other than battles.
please give more details on what exactly you want to do, including an example - I think you're running off in a strange direction and risk wasting a lot of work - because if it is just for a mass-change of data, I would use a multifile text replacement on the json files (there are some advanced text editors that support this) instead of risking damage to the project by writing a plugin for that. Less work, faster and easier that way.
please give more details on what exactly you want to do, including an example

Here's the basic structure I'm planning.

For each type of object that uses notes (actors, classes, etc.) you can specify two "base" objects in the parameters: a "start" object and an "end" object. For each non-base object of a type the plugin will do the following:

1) Copy the object's note.
2) Insert a copy of the start object's note at the beginning.
3) Add a copy of the end object's note to the end.
4) Replace the original note with the modified one.

For a simple example (not what I'm actually trying to do), let's say you want to have a "hard" difficulty setting where your characters are weaker but you want different changes for each class. You can declare variables in the notes for each class for the specific changes to it and then in the "end class" object you'd put the code to apply those numbers.


I think you're running off in a strange direction and risk wasting a lot of work - because if it is just for a mass-change of data, I would use a multifile text replacement on the json files (there are some advanced text editors that support this) instead of risking damage to the project by writing a plugin for that. Less work, faster and easier that way.

Hmm... You may be right. What editor would you recommend? I'm using Sublime right now but I'm not familiar with all the features.
FYI: that is not how the base troop event plugin works, even if it might look to have a similiar process at a simple glance.

I see what you're trying to do here, and it might be a good idea - but I can also see several problems coming up.

If this is just for meta-type tags, then I would use a different way, like what the troop events really do.
Rewrite the meta function so that whenever that one is called, it internally adds the notetag of one designated object to the front any another to the back before continuing processing. I suggest not using 1&2 for that - it is custom to use troop #1 as base troop for convenience, but too many database objects with ID 1 and 2 have default functions implemented that should not be messed with (death state #1 or attack skillk #1 for example)

Doing the same for custom noteparsers will be more difficult, but again I suggest to you to rather try to alias the data structure for a redirect instead of rewriting the stored data.

Original thread: https://forums.rpgmakerweb.com/threads/editing-notes-in-code.75933/