Home > RGSS Script Reference > Scene_Save
Scene_Save
Inherits from: Scene_File
Description: This class handles the aspects of the file selection process that are unique to saving a game.
class Scene_Load < Scene_File
# ------------------------------------
def initialize
super("In which slot would you like to save?")
end
# ------------------------------------
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
# ------------------------------------
def on_cancel
$game_system.se_play($data_system.cancel_se)
if $game_temp.save_calling
$game_temp.save_calling = false
$scene = Scene_Map.new
return
end
$scene = Scene_Menu.new(4)
end
# ------------------------------------
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
end
|
This class has no properties.
What is the Marshalling Library?
The marshalling library allows objects to be stored so that they can be recovered for later use even after the script terminates. This is done using a process called serialization. The objects are converted into a stream of bytes using the Marshal.dump method, and the bytes are read and reconstituted using the Marshal.load method. If several serialized objects are dumped to the same file, as they are in a RPG Maker XP save, they must be reconstituted in the same order they were dumped in order to avoid errors.
|
Initialize
Arguments: None
Local Variables: None
How it Works: This method calls the Scene_File#Initialize method to set up the windows and the help window text.
On_Decision
Arguments: None
Local Variables: None
How it Works: This method processes the effects of the user deciding on a file to save. First, the save sound effect is played, the file is opened, and the write_save_data method is called to serialize the game objects (see below for more information). Control is then transferred either to the map (if the save menu was called using the "Open Save Menu" event command) or to the menu (if the "Save" menu command was selected).
On_Cancel
Arguments: None
Local Variables: None
How it Works: Processes the effects of the user cancelling the save menu. Control is transferred either to the map (if the save menu was called using the "Open Save Menu" event command) or to the menu (if the "Save" menu command was selected).
Write_Save_Data
Arguments: None
Local Variables: None
How it Works: This method serializes the objects that make up the game data. The "Marshal" library takes each object in turn and changes it from an object into a string of bytes that can be stored until the user loads the file. The save count is then incremented.
|
|