Submit Your Article Guild Wars 2 Forum RPG Maker VX.com
 
RPG Maker
 

 Username:
 Password:
   Not a member? Register!



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.

Code


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

Properties


This class has no properties.

Methods


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. 
Syntax
@
@@
$
alias
[array index]
attr_accessor
attr_reader
attr_writer
class
def
do
ensure
for
if
[iterator]
key => value
new
next
nil
redo
require
return
rescue
self
super
undef
unless
until
while
yield

Classes
Arrow_Actor
Arrow_Base
Arrow_Enemy
Game_Actor
Game_Actors
Game_BattleAct
Game_Battler
Game_Character
Game_Common
Game_Enemy
Game_Event
Game_Map
Game_Party
Game_Picture
Game_Player
Game_Screen
Game_SlfSwitch
Game_Switches
Game_System
Game_Troop
Game_Variables
Interpreter
Scene_Debug
Scene_End
Scene_Equip
Scene_File
Scene_Gameover
Scene_Item
Scene_Load
Scene_Map
Scene_Menu
Scene_Name
Scene_Save
Scene_Shop
Scene_Skill
Scene_Status
Scene_Title
Sprite_Battler
Sprite_Character
Sprite_Picture
Sprite_Timer
Spriteset_Battle
Spriteset_Map
Window_Base
Window_Battleresult
Window_Battlestatus
Window_Command
Window_DebugLeft
Window_DebugRight
Window_EquipItem
Window_EquipLeft
Window_EquipRight
Window_Gold
Window_Help
Window_InputNumb
Window_Item
Window_MenuStatus
Window_Message
Window_NameEdit
Window_NameInput
Window_PartyCom
Window_PlayTime
Window_SaveFile
Window_Selectable
Window_ShopBuy
Window_ShopCom
Window_ShopNum
Window_ShopSell
Window_ShopStatus
Window_Skill
Window_SkillStatus
Window_Status
Window_Steps
Window_Target

Other
Class Hierarchy
Global Variables


RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

RPG RPG Revolution is an Privacy Policy and Legal