Selecting what variables to serialize on save

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Currently, when you save your game, RM simply marshals a bunch of objects and that's it.


However, what happens when I want to make it so that I don't want a certain instance variable to be saved?


Does this suggest that my design is bad and should find a way to avoid storing it in the object itself?
 
  • Like
Reactions: Ven

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,158
First Language
English
Primarily Uses
N/A
I'd store it in an object that doesn't get saved. Let's say it's a setting; then I'd have SavedSettings and TempSettings; only the SavedSettings object is stored when saving, but if you want some similar functionality shared between these classes, have them inherit methods one way or the other.
 

Lemur

Crazed Ruby Hacker
Veteran
Joined
Dec 1, 2014
Messages
106
Reaction score
124
First Language
English
Primarily Uses
I almost wish that I could jack an extension onto RM to allow for the usage of something like Neo4j Graph Databases or MongoDB. Definitely more advanced, but the payoffs for flexibility and raw power are worth it to me at least.

In this case though, I'd agree and probably go with a temporary object of some sort that doesn't save.
 

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
Whenever you call Marshal.dump(Object), Ruby calls the method Object.marshal_dump (or Object._dump) before serializing it. Thus if you want to customize your objects serialization, you just need to write your own version of that method. Realize you'll also need to write your own version of marshal_load too in order to reconstitute your object the way you want to. I've done this before using something like this:
 

class My_Objectdef initialize @saved_variable_1 = "Hello" @saved_variable_2 = "World" @unsaved_variable = "!!!"enddef marshal_dump return [ @saved_variable_1, @saved_variable_2 ]enddef marshal_load(dumpped_object) @saved_variable_1 = dumpped_object[0] @saved_variable_2 = dumpped_object[1]endend
Reference: http://www.linuxtopia.org/online_books/programming_books/ruby_tutorial/Reflection_ObjectSpace_and_Distributed__Ruby_Custom_Serialization_Strategy.html
 

Lemur

Crazed Ruby Hacker
Veteran
Joined
Dec 1, 2014
Messages
106
Reaction score
124
First Language
English
Primarily Uses
Assuming RM has JSON support, just serialize objects to JSON from a hash.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Whenever you call Marshal.dump(Object), Ruby calls the method Object.marshal_dump (or Object._dump) before serializing it. Thus if you want to customize your objects serialization, you just need to write your own version of that method. Realize you'll also need to write your own version of marshal_load too in order to reconstitute your object the way you want to. I've done this before using something like this:
How can it be done so that I can have a dozen different scripts all adding custom instance variables to an object, but making sure that only the variables I want to exclude will be excluded?


Also, if someone else decides that they want to exclude their own variables, we would likely end up with two incompatible scripts because they're both overwriting the same method under the assumption that no one else would be doing with.
 

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
#==============================================================================


# ** Game_Temp


#------------------------------------------------------------------------------


# This class handles temporary data that is not included with save data.


# The instance of this class is referenced by $game_temp.


#==============================================================================
 

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,158
First Language
English
Primarily Uses
N/A
Assuming RM has JSON support, just serialize objects to JSON from a hash.
It doesn't sadly. But that's just a different format, it's not relevant to the question at hand :)
 

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

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
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.

Forum statistics

Threads
105,868
Messages
1,017,083
Members
137,583
Latest member
write2dgray
Top