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

Gleen

Veteran
Veteran
Joined
Jun 14, 2012
Messages
98
Reaction score
21
First Language
portuguese
Primarily Uses
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.
 

mobychan

CodeMaster
Veteran
Joined
Mar 23, 2012
Messages
297
Reaction score
45
First Language
German
Primarily Uses
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?
 

Gleen

Veteran
Veteran
Joined
Jun 14, 2012
Messages
98
Reaction score
21
First Language
portuguese
Primarily Uses
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.
 
Last edited by a moderator:

omoney

Ruby Nooby
Veteran
Joined
May 31, 2012
Messages
57
Reaction score
4
First Language
English
Primarily Uses
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?
 

mobychan

CodeMaster
Veteran
Joined
Mar 23, 2012
Messages
297
Reaction score
45
First Language
German
Primarily Uses
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.
 

omoney

Ruby Nooby
Veteran
Joined
May 31, 2012
Messages
57
Reaction score
4
First Language
English
Primarily Uses
Ok. I think I have an idea of what to do now. Thanks.
 

BigEd781

undefined method 'stupid_title' found for nil:NilC
Veteran
Joined
Mar 1, 2012
Messages
940
Reaction score
304
First Language
Dothraki
Primarily Uses
N/A
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.
 

omoney

Ruby Nooby
Veteran
Joined
May 31, 2012
Messages
57
Reaction score
4
First Language
English
Primarily Uses
Good to know, Thanks
 

timk1980

Apprentice
Member
Joined
Mar 15, 2012
Messages
123
Reaction score
42
First Language
English
Primarily Uses
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.
 

omoney

Ruby Nooby
Veteran
Joined
May 31, 2012
Messages
57
Reaction score
4
First Language
English
Primarily Uses
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.
 

Gleen

Veteran
Veteran
Joined
Jun 14, 2012
Messages
98
Reaction score
21
First Language
portuguese
Primarily Uses
I guess its a matter of semantics when you're adding an atribute that won't work with data.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,015
Members
137,563
Latest member
MinyakaAeon
Top