what's the use of "contents"?

Hi people I saw this in the data manager and I was not sure of what it's was use for

#-------------------------------------------------------------------------- # * Create Save Contents #-------------------------------------------------------------------------- def self.make_save_contents contents = {} contents[:system] = $game_system contents[:timer] = $game_timer contents[:message] = $game_message contents[:switches] = $game_switches contents[:variables] = $game_variables contents[:self_switches] = $game_self_switches contents[:actors] = $game_actors contents[😛arty] = $game_party contents[:troop] = $game_troop contents[:map] = $game_map contents[😛layer] = $game_player contents end #-------------------------------------------------------------------------- # * Extract Save Contents #-------------------------------------------------------------------------- def self.extract_save_contents(contents) $game_system = contents[:system] $game_timer = contents[:timer] $game_message = contents[:message] $game_switches = contents[:switches] $game_variables = contents[:variables] $game_self_switches = contents[:self_switches] $game_actors = contents[:actors] $game_party = contents[😛arty] $game_troop = contents[:troop] $game_map = contents[:map] $game_player = contents[😛layer] endwhat's is the use of "contents" in this part? and in what is the use in the other scripts?

thanks for any further answer 🙂
I know what it's used for but I'm terrible at explaining things. Anyway, contents is just the name of the hash. What your looking at is a hash of game objects that are dumped and loaded using Marshal. Say you create a new game object like Game_Quest. It still won't be saved unless you add it to the contents hash. So you'd have

contents[:quests] = $game_quest << This tells RM to dump the $game_quest object into the hash

$game_quest = contents[:quests] << This tells RM to Load the most recent saved hash to $game_quest

Now if your talking about contents in window scripts such as contents.fill_rect ; that's just the bitmap name in a window and it doesn't have any other purpose sense windows are only comprised of sprites and bitmaps.
contents is a hash, which stores the objects that the game persists with savefiles.

In basic terms, it stores the objects that have data specific to the player's file, so that when the file gets loaded, it's all the same.
It's just a temporary storage space that the method uses while building the whole contents of the save file, so it can send back to the caller. Just like any other hash variable that you create.


The :actors, :system and all that are just symbols that are the keys to the hash.
For the save part, basically it puts everything that needs to be saved into a variable named contents, then sends it back to the caller (which is why the last line says "contents"


For the load part, it doesn't necessarily have to be named contents, but of course to be consistent, you do it.
For your "what is the use in other scripts" question, are you referring to the *_Window classes?


They use a variable called contents as the part that will be drawn/written on. I don't have Ace with me, so I'm going by memory (aka guessing) here - I THINK it is a sprite. This variable has absolutely nothing to do with the similarly-named variable in the DataManager class.
BTW, the variable called contents in the DataManager has nothing to do with other scripts (at least if we're talking of the default ones). Windows also use a variable called contents but that's an entirely different thing which Shaz described above
thanks guys! it's make sens I was trying to finds a ways to store my variable or thing for get remember in game!

thanks for all your explaination!

so example if I want a data to be memorize I put them into this? because I think each time I will change or reload the save my variable will get erase in my scripts?
yeah if you want to save extra stuff into the save file, you could put it as another entry in the contents hash during saving, and of course be sure to add the loading for it too.


You could take a look at some of the scripts out there which saves extra stuff into the save file if you need more examples.
thanks for your answer this help me a lots : D !

EDIT : weird...I alias this methods and...it's seemed to not work at all?
it's a module so aliasing it is a bit different, you will need to do something like this

Code:
class << self  alias method_alias methodenddef methodend
Also, if you alias the saving part, make sure that you do something like
Code:
contents = aliased_save_contents_methodcontents[blahblah] = your_contentcontents
so this explique why this was not work!
What is it that you're trying to store? Unless it's a whole new, big class that has lots of arrays (like Items, Actors, Weapons, etc), I just look for somewhere "logical" that already exists to put it. Game_Party, Game_Player and Game_System are all good "containers" that you can add new variables to and have them saved automatically.
Normally, people add them to $game_system. XD
What is it that you're trying to store? Unless it's a whole new, big class that has lots of arrays (like Items, Actors, Weapons, etc), I just look for somewhere "logical" that already exists to put it. Game_Party, Game_Player and Game_System are all good "containers" that you can add new variables to and have them saved automatically.
well it's a wrapper system like the variable wrapper 

and also my system containt TONS of variable and it's need to be keep in save because one of them is the character mood  in scene have to be save  (it's a variable) before getting refresh after a certain moment 

Normally, people add them to $game_system. XD
yeah but my system is standalone xD
It doesn't destroy the stand-alone part since $game_system is present in the game anyways.

Original thread: https://forums.rpgmakerweb.com/threads/whats-the-use-of-contents.41430/