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[:playtime_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[:party] = $game_party contents[:troop] = $game_troop contents[:map] = $game_map contents[:player] = $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?
[RGSS3] Aliasing Save and Load methods
● ARCHIVED · READ-ONLY
-
-
I wouldn't do it that way. I'd just alias the make_save_contents method, and in the aliased method I'd simply call the original and then add my new contents to the end. Same with loading the save file.
-
I've not used Ruby in far too long.
I automatically assumed that because the intent of the line with just the word 'contents' was to return the hash, then it would actually return the hash no matter what (I was reading it as 'return contents'1). Silly me.
So now I have the issue that after aliasing, it no longer seems to recognise the contents variable.
Here's my relavant code:
http://pastebin.com/w85jzFfi
And it won't save, because of the unrecognised method or variable 'contents'
EDIT: Nevermind, fixed it, by setting a new local contents = aliased_old_method. (And I also had removed the args from the loading method)
All Solved now. Thanks Shaz
1I realise now that even this would have been fine with the solution I arrived at. This opens a whole new world of aliasing! -
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.