Others RPG MAKER XP - Save file problem

kR1pt0n1t3

Active Member
Dec 31, 2017
821
975
I have a problem that I don't know how to solve.

The idea:
- After the XY event ends in RPG Maker, call Save Scene and overwrite a save file but only update $game_switches in that file. Other things inside the file leave as it is. After that is done, go to the title screen of the game.

The purpose of this is to allow the player to replay endings after he's seen them. Since all the ending events end with the player going to the title screen of the game, I need to save somewhere information that the player has seen that event before that happens. For that purpose, I made it so XY switch is flipped before the player is transferred to the title screen, and Save Scene is called so that the switch I flipped is saved inside the latest save file.

Ideally, I would've liked it somehow all existing save files would be automatically edited and the switch change saved inside them, but I don't even know where to begin.

Anyhow, I ended up messing around and came up with a way to do it on just one file. But, it's not working as I planned... The solution is probably something stupid but I can't figure it out.

--------------------------
MY THOUGHT PROCESS
--------------------------

There are two functions that I need to adjust to being able to pull this off.

1ST FUNCTION
Code:
def on_decision(filename)
    $game_system.se_play($data_system.save_se)
    file = File.open(filename, "wb")
    write_save_data(file)
    file.close
    if $game_temp.save_calling
       $game_temp.save_calling = false
       $scene = Scene_Map.new
       return
    end
      $scene = Scene_Menu.new(4)
end
2ND FUNCTION
Code:
def write_save_data(file)
      characters = []
      for i in 0...$game_party.actors.size
        actor = $game_party.actors[i]
        characters.push([actor.character_name, actor.character_hue])
      end
      Marshal.dump(characters, file)
      Marshal.dump(Graphics.frame_count, file)
      $game_system.save_count += 1
      $game_system.magic_number = $data_system.magic_number
      Marshal.dump($game_system, file)
      Marshal.dump($game_switches, file)
      Marshal.dump($game_variables, file)
      Marshal.dump($game_self_switches, file)
      Marshal.dump($game_screen, file)
      Marshal.dump($game_actors, file)
      Marshal.dump($game_party, file)
      Marshal.dump($game_troop, file)
      Marshal.dump($game_map, file)
      Marshal.dump($game_player, file)
end
So, the first thing I did was to replace the 3rd line inside the first function with all this:

Code:
if $game_switches[1100] == true
  file = File.open(filename, "rb+")
else
  file = File.open(filename, "wb")
end
Before the Save Screen is called inside the ending event, I flipped a switch 1100 to ON so the script knows it only needs to update $game_switches inside an existing save file. To that end, I made inside the first function an if-else loop. According to the wiki or ruby, "rb+" is for when I only want to update something inside the existing file so I opened the file with "rb+" instead of "wb" that deletes everything inside the file first.

After that I edited the 2nd function to this:
Code:
def write_save_data(file)
  if $game_switches[1100] == false
      characters = []
      for i in 0...$game_party.actors.size
        actor = $game_party.actors[i]
        characters.push([actor.character_name, actor.character_hue])
      end
      Marshal.dump(characters, file)
      Marshal.dump(Graphics.frame_count, file)
      $game_system.save_count += 1
      $game_system.magic_number = $data_system.magic_number
      Marshal.dump($game_system, file)
      Marshal.dump($game_variables, file)
      Marshal.dump($game_self_switches, file)
      Marshal.dump($game_screen, file)
      Marshal.dump($game_actors, file)
      Marshal.dump($game_party, file)
      Marshal.dump($game_troop, file)
      Marshal.dump($game_map, file)
      Marshal.dump($game_player, file)
  end
      Marshal.dump($game_switches, file)
end
I moved the "Marshal.dump($game_switches, file)" outside the IF loop so only that part gets updated in case switch 1100 is FALSE. If 1100 is TRUE(which in my case it is), everything inside the if loop will be skipped.

Everything works exactly as I thought it would expect for this error when I try to open a save file I saved after I did these changes.



This is the script it's referring to inside the error that I didn't change at all...
You don't have permission to view the spoiler content. Log in or register now.