MZ The use of $gameSystem to save data

Dear plugin creators / javascript aficionados,

Whats the consensus of using $gameSystem to store data for plugins in RPG maker MV/MZ?

I am developing an item upgrade system for MZ and one of the challenges I have to tackle is creating independent items. Game_Item doesn't store any unique data (it only references $dataItems / $dataWeapons etc.) so I have created a map that is saved in $gameSystem that stores a reference to the item as well as assigning the item a unique id. I can now access unique items in the game by calling $gameSystem._uniqueItems (returns a map). As I expand the system to include tracking upgrades for items, all of this data will be saved in $gameSystem.

$gameSystem seems like a noob friendly place to store data; not to mention its globally accessible. I see more advanced plugin makers such as Yanfly make their own class and then hook into the save/load methods to save their data. And then plugins such as SRPG Gear MZ using $gameSystem extensively despite being a fairly complex plugin ecosystem. But is there really any harm in using $gameSystem to store data?
A couple of possible issues off the top of my head:
  • Naming conflicts - another plugin might define a property on Game_System with the same name as yours, creating an incompatibility. But this can apply to any approach.

  • Save residue - in the unlikely event that you use the plugin, make a save, then remove the plugin, any custom data it added to $gameSystem would generally remain as bloat.
Like you say, the common alternative is to patch 3 DataManager methods: createGameObjects, makeSaveContents, and extractSaveContents. That's not really much work either, but it can help to make the resulting plugin more robust. 👋
Naming conflicts - another plugin might define a property on Game_System with the same name as yours, creating an incompatibility. But this can apply to any approach.
Excellent answer; I just want to add one thing. If you are really concerned about conflicts, simply add something unique like your name to your attribute. I personally use _mk_ as my initials.

Code:
$gameSystem._mk_independentItems = { }
I do use this method sometimes; if can be a quick-and-dirty way to conveniently add additional data without having to create a completely new game object to do so. I'm wary of it for the same potential risks as caethyril pointed out, though.
A couple of possible issues off the top of my head:
  • Naming conflicts - another plugin might define a property on Game_System with the same name as yours, creating an incompatibility. But this can apply to any approach.

  • Save residue - in the unlikely event that you use the plugin, make a save, then remove the plugin, any custom data it added to $gameSystem would generally remain as bloat.
Like you say, the common alternative is to patch 3 DataManager methods: createGameObjects, makeSaveContents, and extractSaveContents. That's not really much work either, but it can help to make the resulting plugin more robust. 👋
Good points.

What if I'm just wanting to create a global variable to track something?
For example, I have a custom font plugin that stores the previous font used.
I'm just using $gameSystem to do this ($gameSystem._fontName)
Would this be a legitimate use?
If I go down the Datamanager methods, I'll also have to use a Imported.Boomy = true (which I seem to see in many plugins), which will temporarily store data (which can then be read or written using dataManager) correct?
What if I'm just wanting to create a global variable to track something?
For example, I have a custom font plugin that stores the previous font used.
  • If you need it to be saved, then it's the same case as already mentioned.
  • If it doesn't need to be saved, then storing it on a saved object will bloat saves.
A common approach for (unsaved) global plugin values is to define a global variable of type object, i.e. a "namespace". That might be 1 namespace per plugin; it might be a single namespace for the author with properties that are plugin namespaces; it might be some other structure. Data can then be stored as properties of the applicable namespace.

If I go down the Datamanager methods, I'll also have to use a Imported.Boomy = true (which I seem to see in many plugins), which will temporarily store data (which can then be read or written using dataManager) correct?
No. The Imported namespace is just a convention used by many plugin authors to make it easier to check for the existence and/or version of other plugins. It can be useful, e.g. for plugins that extend other plugins. It is not mandatory, and if used conventionally is just constant data.

I guess plugins that create files might save version information etc to those files, but generally Imported has nothing to do with the DataManager.

Original thread: https://forums.rpgmakerweb.com/threads/the-use-of-gamesystem-to-save-data.175801/