I wanted to add a custom $game_* object I'd made and this meant saving and loading it, so I slightly edited DataManager like so:
#==============================================================================# DataManager#==============================================================================module DataManager #-------------------------------------------------------------------------- # Edited to create the hash outside the make_save_* methods. #-------------------------------------------------------------------------- def self.save_game_without_rescue(index) File.open(make_filename(index), "wb") do |file| $game_system.on_before_save # Make Header save_header = {} make_save_header(save_header) Marshal.dump(save_header, file) # Make Contents save_contents = {} make_save_contents(save_contents) Marshal.dump(save_contents, file) @last_savefile_index = index end return true end #-------------------------------------------------------------------------- # This method now only adds objects to header (so now can be aliased). #-------------------------------------------------------------------------- def self.make_save_header(header) header[:characters] = $game_party.characters_for_savefile header[😛laytime_s] = $game_system.playtime_s end #-------------------------------------------------------------------------- # This method now only adds objects to contents (so now can be aliased). #-------------------------------------------------------------------------- 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 end end # DataManagerAre there any problems with this? I realise that this approach is slightly less... functional, but it allows much easier aliasing of the make_save_contents method.
Thoughts?
#==============================================================================# DataManager#==============================================================================module DataManager #-------------------------------------------------------------------------- # Edited to create the hash outside the make_save_* methods. #-------------------------------------------------------------------------- def self.save_game_without_rescue(index) File.open(make_filename(index), "wb") do |file| $game_system.on_before_save # Make Header save_header = {} make_save_header(save_header) Marshal.dump(save_header, file) # Make Contents save_contents = {} make_save_contents(save_contents) Marshal.dump(save_contents, file) @last_savefile_index = index end return true end #-------------------------------------------------------------------------- # This method now only adds objects to header (so now can be aliased). #-------------------------------------------------------------------------- def self.make_save_header(header) header[:characters] = $game_party.characters_for_savefile header[😛laytime_s] = $game_system.playtime_s end #-------------------------------------------------------------------------- # This method now only adds objects to contents (so now can be aliased). #-------------------------------------------------------------------------- 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 end end # DataManagerAre there any problems with this? I realise that this approach is slightly less... functional, but it allows much easier aliasing of the make_save_contents method.
Thoughts?