Proper way to store a variable (to be saved)

I want to create a variable for example an array and add values to it, with a pluginCommand.
but want that array to be stored with the game saved data. I know it might be a simple question, but I think is the basis of many plugins...
and I wanted to know the proper way to do it.

Thank you for your time 😀  
You'll want to add it as a property to the Game_System class, like so:

(function(){ var _GS_init Game_System.prototype.initialize = function() { _GS_init.call(this); // Makes sure to do the stuff that was in the function before this._myArray = []; // Adds in our own array. }})();Now you can access the array via $gameSystem._myArray and put things in at your hearts content, and it'll be saved with save files. Just be careful that old save files won't have the data you're looking for, since they would have been made before a plugin added this code into the game.
You'll want to add it as a property to the Game_System class, like so:

(function(){ var _GS_init Game_System.prototype.initialize = function() { _GS_init.call(this); // Makes sure to do the stuff that was in the function before this._myArray = []; // Adds in our own array. }})();Now you can access the array via $gameSystem._myArray and put things in at your hearts content, and it'll be saved with save files. Just be careful that old save files won't have the data you're looking for, since they would have been made before a plugin added this code into the game.
Thank you!! very much really fast response 😀

Can the variable be of any type?! Number, Array, String and even Hash table?!

Another thing, isn't there something missing after:

Code:
var _GS_init
Thank you!! very much really fast response 😀

Can the variable be of any type?! Number, Array, String and even Hash table?!

Another thing, isn't there something missing after:

var _GS_init
Oh, yes, whoops, I forgot to actually set it equal to the function 😛

And yes, the variable can be any type.

(function(){ var _GS_init = Game_System.prototype.initilize; Game_System.prototype.initialize = function() { _GS_init.call(this); // Makes sure to do the stuff that was in the function before this._myArray = []; // Adds in our own array. this._myObject = {}; // Adds in a JS Object. this._myNum = 0; // Adds in a Number. this._myStr = ""; // Adds in a String. this._myBool = true; // Adds in a boolean (true/false). }})();Of course, I'd recommend you change the variable names 🙂 .
Oh, yes, whoops, I forgot to actually set it equal to the function 😛

And yes, the variable can be any type.

(function(){ var _GS_init = Game_System.prototype.initilize; Game_System.prototype.initialize = function() { _GS_init.call(this); // Makes sure to do the stuff that was in the function before this._myArray = []; // Adds in our own array. this._myObject = {}; // Adds in a JS Object. this._myNum = 0; // Adds in a Number. this._myStr = ""; // Adds in a String. this._myBool = true; // Adds in a boolean (true/false). }})();Of course, I'd recommend you change the variable names 🙂 .
Thank you very much 🙂

I think I have it cleared 😉

BTW: I see sometime in plugins functions been added to Game_System... by this I mean:

Game_System.prototype.blahblah = function(a) { ... }

for example this happens in the EnemyBook plugin... is this the right way to do it?

Is it better doing it other way? I though it would be more organized to create the variable inside Game_System

But have the functions store inside a Module.. for example. What do you suggest?

Thanks again... I'm really lovin JavaScripting.. and want to learn it the best way possible ;D
BTW: I see sometime in plugins functions been added to Game_System... by this I mean:

Game_System.prototype.blahblah = function(a) { ... }

for example this happens in the EnemyBook plugin... is this the right way to do it?

Is it better doing it other way? I though it would be more organized to create the variable inside Game_System

But have the functions store inside a Module.. for example. What do you suggest?

Thanks again... I'm really lovin JavaScripting.. and want to learn it the best way possible ;D
It's really a matter of personal preference, and who should be able to use the functions. Personally, I'd avoid it if I don't really need it to be in the system. In Ace I used to put stuff there for convenience when using script calls, but now with plugin commands that's not really as necessary. So doing so isn't necessarily bad or good (as far as I know), but it's really what you prefer.
I would create a static container class that takes a value in and pushes it to the array and then a method called getArray or something that gets the entire array.
(function(){ var _GS_init = Game_System.prototype.initialize;
Game_System.prototype.initialize = function()
{ _GS_init.call(this); // Makes sure to do the stuff that was in the function before
this._myArray = []; // Adds in our own array.
this._myObject = {}; // Adds in a JS Object.
this._myNum = 0; // Adds in a Number. this._myStr = ""; // Adds in a String.
this._myBool = true; // Adds in a boolean (true/false). }})();



I fixed a typo above.  Btw, thank you.  This was something I've been looking for for quite a while!

Original thread: https://forums.rpgmakerweb.com/threads/proper-way-to-store-a-variable-to-be-saved.50867/