I had this idea, but I finally decided to actually implement it. Normally, game data is stored in the files in a particular order. If the order is changed or new data is added, the savegame can't load, or the game will crash eventually. But if I use a loop and check for the loaded objects' class in each iteration and assign them to the respected global variable, data will be loaded properly no matter how badly the order is changed. After the loop, if any globals are still 'nil', I create a new instance and assign it. Basically, the read_save_data method will be something like this:
def read_save_data(file)
characters = frame_count = $game_system = $game_switches = $game_variables = nil
$game_self_switches = $game_screen = $game_actors = $game_party = nil
$game_troop = $game_map = $game_player = nil
data = [characters, frame_count, $game_system, $game_switches,
$game_variables, $game_self_switches, $game_screen, $game_actors,
$game_party, $game_troop, $game_map, $game_player]
# Checking each loaded object's class and assigning accordingly
while !data.any? {|obj| obj == nil}
stuff = Marshal.load(file)
if stuff.is_a?(Array)
characters = stuff
elsif stuff.is_a?(Numeric)
frame_count = stuff
elsif stuff.is_a?(Game_System)
$game_system = stuff
end
#
#and so on..
#
Graphics.frame_count = frame_count
end
#Creating new instances of extra objects
$ams = AMS.new if $ams == nil
$item_bag = Item_Bag.new if $item_bag = nil
#
#and so on..
#
end
The only catch is that data of same classes can't be recognised (like arrays and numbers). Even that can be corrected by checking the arrays, but numbers...
So... discuss