Let's share your RMMV plugin notetag setups

This post aims to incite you to share your ways to implement notetags in RMMV plugins.

In general, we don't want to edit the data JSON files directly, so there are generally 2 notetag reading timings:

1. Upon the start of the game

2. Upon using those notetags

I'll start by sharing my notetag implementation template with the 1st notetag reading timing:

Spoiler
Author_Name.Plugin_Name = { /* General form: data_type: { note_name: {}, }, */ data_type_1: { note_name_i_j: {} /* ... */ }, data_type_2: { note_name_i_j: {} /* ... */ }, data_type_3: { note_name_i_j: {} /* ... */ }, /* ... */ data_type_n: { note_name_i_j: {} /* ... */ }, /* General form: $dataTypes.forEach(function(data) { if (data) { this.load_notes("type", data); } }); */ load_all_notes: function() { $dataTypes1.forEach(function(data) { if (data) { this.load_notes("type1", data); } }); $dataTypes2.forEach(function(data) { if (data) { this.load_notes("type2", data); } }); $dataTypes3.forEach(function(data) { if (data) { this.load_notes("type3", data); } }); /* ... */ $dataTypesN.forEach(function(data) { if (data) { this.load_notes("typeN", data); } }); return true; }, // load_all_notes // Additional notetag loading functions will be added when appropriate /* type: The type of the data data: The data to have its notetags read */ load_notes: function(type, data) { var id = data.id;        Object.keys(this[type]).forEach(function(note) {            this[type][note][id] = note_init_val;        }); data.note.split(/[\r\n]+/).forEach(function(line) { // The notetag reading implementations are written here // }); } // load_notes}; // Author_Name.Plugin_Name/*---------------------------------------------------------------------------- * * Edit class: DataManager *----------------------------------------------------------------------------*/DataManager.isDatabaseLoaded = (function(isDatabaseLoadedPluginName) { return function() { // Rewritten isDatabaseLoadedPluginName.apply(this, arguments) && Author_Name.Plugin_Name.load_all_notes(); / };})(DataManager.isDatabaseLoaded);
I wrapped my entire setup in Author_Name.Plugin_Name to hope that mine won't pollute any "public namespace" like DataManager or even the global one.

Now I can access the notetag with name "notetag_name" stored in data with type "data_type" and id data_id using the below plugin call:

Author_Name.Plugin_Name["data_type"][notetag_name][data_id]For instance🙁DoubleX RMMV Equip Prerequisites)

Spoiler
DoubleX_RMMV.Equip_Prerequisites = { /* General form: data_type: { note_name: {}, }, */ weapons: { no_weapon_req: {}, no_armor_req: {}, weapon_req: {}, armor_req: {}, stat_req: {}, var_req: {}, }, armors: { no_weapon_req: {}, no_armor_req: {}, weapon_req: {}, armor_req: {}, stat_req: {}, var_req: {}, }, /* General form: $dataTypes.forEach(function(data) { if (data) { this.load_notes(data, "type"); } }); */ load_all_notes: function() { $dataWeapons.forEach(function(data) { if (data) { this.load_notes(data, "weapons"); } }); $dataArmors.forEach(function(data) { if (data) { this.load_notes(data, "armors"); } }); }, // load_all_notes /* data: The data to have its notetags read type: The type of the data */ load_notes: function(data, type) { var id = data.id.toString(); Object.keys(this[type]).forEach(function(note) { this[type][note][id] = []; }); var lines = data.note.split(/[\r\n]+/); var no_weapon_note = /<no weapon req:\s*(\d+)>/; var no_armor_note = /<no armor req:\s*(\d+)>/; var weapon_note = /<weapon req:\s*(\d+)>/; var armor_note = /<armor req:\s*(\d+)>/; var stat_note = /<stat req:\s*(.+),\s*(\w+),\s*(\w+)>/; var var_note = /<var req:\s*(\d+),\s*(\w+),\s*(\w+)>/; var num, vals; lines.forEach(function(line) { if (line.test(no_weapon_note)) { vals = line.match(no_weapon_note); this[type]["no_weapon_req"][id].push(Number(vals[0])); } else if (line.test(no_armor_note)) { vals = line.match(no_armor_note); this[type]["no_armor_req"][id].push(Number(vals[0])); } else if (line.test(weapon_note)) { vals = line.match(weapon_note); this[type]["weapon_req"][id].push(Number(vals[0])); } else if (line.test(armor_note)) { vals = line.match(armor_note); this[type]["armor_req"][id].push(Number(vals[0])); } else if (line.test(stat_note)) { vals = line.match(stat_note); num = Number(vals[2]); if (!isNaN(num)) { vals[2] = num; } this[type]["stat_req"][id].push(vals); } else if (line.test(var_note)) { vals = line.match(var_note); vals[0] = Number(vals[0]); num = Number(vals[2]); if (!isNaN(num)) { vals[2] = num; } this[type]["var_req"][id].push(vals); } }); }, // load_notes};//----------------------------------------------------------------------------//// * Edit class: DataManager ////----------------------------------------------------------------------------//DataManager.loadDatabase = (function(loadDatabaseEquipPrerequisites) { return function() { loadDatabaseEquipPrerequisites.apply(this, arguments); DoubleX_RMMV.Equip_Prerequisites.load_all_notes(); // Added };})(DataManager.loadDatabase);
What do you think about such setups? What's your setup instead and how you think about yours as well? Let's share your setups and comments on them here 🙂
i usually wrap the comment / notetags call inside the object that needed them:

Event notetags / commenttag -> Game_Event

Equipment notetags -> usually Game_Actor.

but if i require to save to savefile and change the value (dynamic). i may place it in Game_System

i also usually create 1 function for each notetags. not wise because that means repeated fetching comment... but it easier to manage.

especially like you did above... for me it's harder to debug if there's error in the regexp (just for me... hope not offend you).

some example code of what i usually do:

Game_Interpreter.prototype.getDecorMap = function(item) {    var mastermap = 0;    comment = item.note;    if(comment.match(/<decor_map:\s*(\d+)?>/im)) var mastermap = Number(comment.match(/<decor_map:\s*(\d+)?>/im)[1]);    return mastermap;};Game_Interpreter.prototype.getDecorEventId = function(item) {    var decorItemId = 0;    comment = item.note;    if(comment.match(/<decor_id:\s*(\d+)?>/im)) var decorItemId = Number(comment.match(/<decor_id:\s*(\d+)?>/im)[1]);    return decorItemId;};taken from my plugin in development... i might change it to Game_System though so it can be accessed anywhere using $gameSystem

in Ace... i created Notetags grabber scripts... but then i realize if i use that... then the scripts i wrote will have dependencies to that script. people will have to download extra files... i also type of scripter that dislike core script. i rather type many times but make the script / plugin able to executed by itself (stand alone).

but it's a matter of personal opinion....
Fully embraces JSON and javascript libraries (note below code snippets are somewhat out of date since I've gone ahead and improved it). Also not compatible with many popular game engine's note tag methods since it expects the note object to be a string representation of JSON. If anything I'm leaning more and more towards just editing the plain JSON files instead of the in game database editor for most things. Except for the map editor, animations, and events.

https://gist.github.com/xhh2a/1d22e26c5c14445ae18f
I've checked this part of the default RMMV codebase:

Spoiler
DataManager.extractMetadata = function(data) { var re = /<([^<>:]+)🙂?)([^>]*)>/g; data.meta = {}; for (; { var match = re.exec(data.note); if (match) { if (match[2] === ':') { data.meta[match[1]] = match[3]; } else { data.meta[match[1]] = true; } } else { break; } }};
And also checked that quite some plugin developers are conforming to this setup, so I changed my notetag setup to this too:

Spoiler
AuthorNameRMMV.PluginName = { loadAllNotes: function() { $dataTypeI.forEach(function(data) { if (data) { AuthorNameRMMV.PluginName.loadDataTypeINotes(data); } }); return true; }, // loadAllNotes // data: The data to have its notetags read loadDataTypeINotes: function(data) { data.meta.notetagNameI = {}; // Implements the notetag reading mechanisms here // } // loadDataTypeINotes}; // AuthorNameRMMV.PluginName/*----------------------------------------------------------------------------* * Edit class: DataManager*----------------------------------------------------------------------------*/DataManager.isDatabaseLoaded = (function(isDatabaseLoadedPluginName) { return function() { // Rewritten return isDatabaseLoadedPluginName.apply(this, arguments) && AuthorNameRMMV.PluginName.loadAllNotes(); // };})(DataManager.isDatabaseLoaded);
For example(DoubleX RMMV State Triggers):

Spoiler
load_all_notes: function() { $dataStates.forEach(function(data) { if (data) { DoubleX_RMMV.State_Triggers.load_state_notes(data); } }); return true; }, // load_all_notes // data: The data to have its notetags read load_state_notes: function(data) { data.meta.state_triggers = {}; var triggers = data.meta.state_triggers; var timing; data.note.split(/[\r\n]+/).forEach(function(line) { if (line.match(/<(\w+) state trigger:\s*(\w+)\s*,\s*(\w+)\s*>/)) { timing = RegExp.$1; triggers[timing] = triggers[timing] || []; triggers[timing].push([RegExp.$2, RegExp.$3]); } }); } // load_state_notes
I don't use data.meta.notetagName directly as it seems to me that the default meta only works for this type of notetag:

<notetagName:notetagData>

But sometimes I'll have to use some other notetag formats, so I think I'll kep using custom reading mechanisms instead of always sticking to the default meta.
I just use the meta, Zero problems so far. Super easy.
My friend made a script that parses note tags and gives you back an array of objects allowing you to have multiple note tags of the same type or different types.

Original thread: https://forums.rpgmakerweb.com/threads/lets-share-your-rmmv-plugin-notetag-setups.49315/