RPG Maker
 

 Username:
 Password:
   Not a member? Register!

Home > RGSS Script Reference > Scene_Load

Scene_Load


Inherits from: Scene_File

Description: This class handles the aspects of the file selection process that are unique to loading a game.

Code


class Scene_Load < Scene_File
# ------------------------------------
 def initialize
    $game_temp = Game_Temp.new
    $game_temp.last_file_index = 0
    latest_time = Time.at(0)
    for i in 0..3
      filename = make_filename(i)
      if FileTest.exist?(filename)
        file = File.open(filename, "r")
        if file.mtime > latest_time
          latest_time = file.mtime
          $game_temp.last_file_index = i
        end
        file.close
      end
    end
    super("Which file do you want to load?")
  end
# ------------------------------------  
  def on_decision(filename)
    unless FileTest.exist?(filename)
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    $game_system.se_play($data_system.load_se)
    file = File.open(filename, "rb")
    read_save_data(file)
    file.close
    $game_system.bgm_play($game_system.playing_bgm)
    $game_system.bgs_play($game_system.playing_bgs)
    $game_map.update
    $scene = Scene_Map.new
  end
# ------------------------------------  
  def on_cancel
    $game_system.se_play($data_system.cancel_se)
    $scene = Scene_Title.new
  end
# ------------------------------------  
  def read_save_data(file)
    characters = Marshal.load(file)
    Graphics.frame_count = Marshal.load(file)
    $game_system        = Marshal.load(file)
    $game_switches      = Marshal.load(file)
    $game_variables     = Marshal.load(file)
    $game_self_switches = Marshal.load(file)
    $game_screen        = Marshal.load(file)
    $game_actors        = Marshal.load(file)
    $game_party         = Marshal.load(file)
    $game_troop         = Marshal.load(file)
    $game_map           = Marshal.load(file)
    $game_player        = Marshal.load(file)
    if $game_system.magic_number != $data_system.magic_number
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    $game_party.refresh
  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 checks to see which files exist and sets up the data that will be shown on the load screen. First, this screen will be invoked from the title screen, so a new Game_Temp object needs to be created until the serialized data is loaded. The main body of this method determines which save file was created most recently so that the value of $game_temp.last_file_index can be set to the appropriate file. The latest time is first set to the value of Time.at(0), meaning 0 seconds since 1970. Then the for loop checks each of the four files to see if the they exist. If they do and the last modified time of any file is greater than the latest time at that point, then $game_temp.last_file_index is set the index of that file.

On_Decision

Arguments: None
Local Variables: None

How it Works: This method processes the effects of the user deciding on a file to load. If the file doesn't exist, then the buzzer sound effect is played. If it does, then the load sound effect is played, the file is opened, and the read_save_data method is called to reconstitute the serialized game objects (see below for more information). Control is then transferred to the map on which the game was saved, with the music and BGS from that map playing.

On_Cancel

Arguments: None
Local Variables: None

How it Works: Processes the effects of the user cancelling the load menu. The cancel sound effect is played and the user is returned to the title screen.

Read_Save_Data

Arguments: None
Local Variables: None

How it Works: This method reconstitutes the serialized objects that were saved. The "Marshal" library grabs each serialized object in turn and changes it from a string of bytes into an object that can be understood by the program. The if $game_system.magic_number != $data_system.magic_number clause checks the "magic number" against the magic number stored in the system data. This number is generated by doing some (unknown) transformation on the state of the game data at the time it's saved. This transformation is done again when the data is loaded. If the two values differ, then the game has been edited, so there can be no guarantee that the map is as it was when the game was saved, so the map data is recreated from scratch. 
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.

By continuing past this page, and by your continued use of this site, you agree to be bound by and abide by the Terms of Use.
©2004 - 2008 RPG RPG Revolution, All Rights Reserved. Contact Us · Privacy Policy · Legal Disclaimer
eXTReMe Tracker