Can we make Global Variables that get Safed?

We have the standard $game_variables[id] that are automaticly safed when the Player safes his Game.

But is it possible to create own global variables that are getting safed automaticly?

Is there maybe a inbuild Scriptequivalent for that to use in Eventcommand Script?

Maybe something like $myvariable[1] or $myvariable[15000] and would it be safed automaticly?

And how much would the safefile increase if i have for example 50 000 of that Variables defined with number values in it?

Sorry Iam not a Scripter so please explain with Words simple ones understand 🙂
rather than creating a code to save a new global variable. why don't use existing one...

namely $gameSystem.

here's example code to create a variable inside Game_System:

// alias method. this will create variable in game system to store the resaved map eventsvar est_event_size_Game_System_initialize = Game_System.prototype.initialize;Game_System.prototype.initialize = function() {  est_event_size_Game_System_initialize.call(this);  this._est_custom_passage_map = {};};usage:

$gameSystem._est_custom_passage_map$gameSystem is automatically saved. so we don't need extra code
Sorry i dont understand your answer. Can you pick me up where iam ?
Looks like estriole's answer was meant for MV.

But All you need to do is to create a global variable inside an existing "Game" object.

I.e.: Lets say I want to store a variable called "Inventary" for the player, so I'll add this script to my project:
 

class Game_Player attr_accessor :inventary @inventaryendSo, everytime I use "$game_player.inventary" I can either get or change it's value, and when I save the game, this value will be safe aswell, because the game will save the Game_Player instance as it is.

PS.: Maybe this is not fully right, I've been a few months away from RPG Maker, but I guess the idea is right ^^
Why would you want to do that?


Please explain what sort of system you have that requires you to have global variables (global variables are good things to try and avoid). We will then be able to tell you if you're using the right approach to start with, or if there's a better way, and help you get it working.


There is nothing stopping you from creating them, but you will have to modify scripts that create a new game, load a saved game, and save a current game in order to do it correctly. In short, there are better ways, and if you explain what you're trying to achieve rather than how, that will allow us to help you with the "how", which may not be the same method you have in mind.

Original thread: https://forums.rpgmakerweb.com/threads/can-we-make-global-variables-that-get-safed.49310/