[Ace] How to get RPG Maker to save and load a variable?

Not sure why you would need to post to reaffirm a fact, also you can dump the information of nearly any object, so it is possible to save the contents of an instance variable.
Sorry, i was going to elaborate on that but before i needed to test something and then i got sleepy haha. I don't know what omoney means by saving instances variables so i assume he just wants to save the value of @somevariable.

Instances variables belongs to specific objects and can be referenced from any method of their class or subclass but the value of any unintialized instance variable is nil, so if he saves a instance variable when he loads the game that variable value will be nil. And if he initializes it again, it will recieve the first value he asigned and not the saved one.

There's another problem, he can't simply put the code below in make_save_contents:



Code:
contents[:test] = @test
Since @test won't be found if isn't initialized inside DataManager. The same for extract_save_contents, but as i said above it will get the original value and not the saved one.

The right way to save an instance variable is through accessors, seting them inside objects that will be saved. So you're not necessarily saving an instance variable but an atribute to that object.

I'm not sure if i explained it right (my english is not that good so it limits me...) or if i'm missing something but as far as i understand ruby and the rgss api, thats it.
I'd say you can save instance variables, but only, if they are part of the information in a global variable, or how else would the Player and his comrades keep their Level/HP/MP... after saving?
I'd say you can save instance variables, but only, if they are part of the information in a global variable, or how else would the Player and his comrades keep their Level/HP/MP... after saving?
Yep, that's right, its what i said about accessors, you can save instances variavles only if they're atributes of a object wich will be saved.
Thanks for all the responses. I am not quite sure how to save and load instance variables or use accessors though. If i define an instance variable @variable inside inside GameInterpreter in a script how would I save it and load it?
You'd have to save a Global Variable (like described above) which is an instance of Game_Interpreter.

Every instance variable of that instance will be saved with it.

Saving a Global Variable is kinda the same as making a "screenshot" of the information inside the instance you save.
Ok. I think I have an idea of what to do now. Thanks.
Just to clear things up here; yes, you can serialize (save) instance variables. An instance variable is simply a member of a type that is specific to an instance of said type (i.e., each instance gets a distinct copy). There is absolutely nothing that would prevent you from saving them between sessions.
Good to know, Thanks
Just to add another option (which may or may not be a "good" option), you can always add instance variables to one of the classes like Game_System or Game_Player, that already gets saved, then you don't have to worry about specially coding to handle the save.
hm thats true. Right now I just made another class and stuck it inside a global variable and save and load that variable. I wonder which one is more efficient or the preferred practice.
I guess its a matter of semantics when you're adding an atribute that won't work with data.

Original thread: https://forums.rpgmakerweb.com/threads/ace-how-to-get-rpg-maker-to-save-and-load-a-variable.2640/