Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

1 Save Lot / AutoLoad Saved Game

1 Save Slot / AutoLoad Saved Game
by Kyonides-Arkanthos


Purpose of The Script

This is a simple script that allows you to save your game data in a single data file (not the 4 as always) and if you want to load it, it'll do it automatically.

Technically, it's just a modification of both scripts, Scene_Title and Scene_Menu.

SCRIPT

Version 1.0.1
[rgss]# 1 Save Slot / AutoLoad Saved Game
#  by Kyonides-Arkanthos
#  v 1.0.1 - 08.10.2010
#  v 1.0.0 - 03.10.2010
class Scene_Title
  def command_continue
    return $game_system.se_play($data_system.buzzer_se) if !@continue_enabled
    $game_system.se_play($data_system.decision_se) # Play decision SE
    load_saved_file
  end
 
  def load_saved_file
    $game_system.se_play($data_system.load_se) # Play load SE
    file = File.open('Save1.rxdata', 'rb') # Read save data
    read_save_data(file)
    file.close
    # Restore BGM and BGS
    $game_system.bgm_play($game_system.playing_bgm)
    $game_system.bgs_play($game_system.playing_bgs)
    $game_map.update # Update map (run parallel process event)
    $scene = Scene_Map.new # Switch to map screen
  end
 
  def read_save_data(file)
    characters = Marshal.load(file) # Read character data for drawing save file
    Graphics.frame_count = Marshal.load(file) # Read frame count (4 play time)
    # Read each type of game object
    $game_temp          = Game_Temp.new # Maker new Game_Temp class (bug fix)
    $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 magic number is different from when saving
    # (if editing was added with editor)
    if $game_system.magic_number != $data_system.magic_number
      $game_map.setup($game_map.map_id) # Load map
      $game_player.center($game_player.x, $game_player.y)
    end
    $game_party.refresh # Refresh party members
  end
end
 
class Scene_Menu
  def update_command
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to map screen
      $scene = Scene_Map.new
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # If command other than save or end game, and party members = 0
      if $game_party.actors.size == 0 and @command_window.index < 4
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Branch by command window cursor position
      case @command_window.index
      when 0  # item
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to item screen
        $scene = Scene_Item.new
      when 1..3  # skill equipment & status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 4  # save
        # If saving is forbidden
        if $game_system.save_disabled
          # Play buzzer SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Save the game but do not exit the current scene
        save_game_data
      when 5  # end game
        # Save the game before going to the next scene
        save_game_data
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to end game screen
        $scene = Scene_End.new
      end
      return
    end
  end
 
  def save_game_data
    $game_system.se_play($data_system.save_se) # Play save SE
    file = File.open('Save1.rxdata', 'wb') # Write save data
    write_save_data(file)
    file.close
    # If called from event
    if $game_temp.save_calling
      # Clear save call flag
      $game_temp.save_calling = false
      # Switch to map screen
      $scene = Scene_Map.new
      return
    end
    # Switch to menu screen
    $scene = Scene_Menu.new(4)
  end
 
  def write_save_data(file)
    # Make character data for drawing save file
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors
      characters.push([actor.character_name, actor.character_hue])
    end
    # Write character data for drawing save file
    Marshal.dump(characters, file)
    # Write frame count for measuring play time
    Marshal.dump(Graphics.frame_count, file)
    # Increase save count by 1
    $game_system.save_count += 1
    # Save magic number
    # (A random value will be written each time saving with editor)
    $game_system.magic_number = $data_system.magic_number
    # Write each type of game object
    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
[/rgss]

Version 1.0.0
[rgss]# 1 Save Slot / AutoLoad Saved Game
#  by Kyonides-Arkanthos
#  v 1.0 - 03.10.2010
class Scene_Title
  def command_continue
    return $game_system.se_play($data_system.buzzer_se) if !@continue_enabled
    $game_system.se_play($data_system.decision_se) # Play decision SE
    load_saved_file
  end
 
  def load_saved_file
    $game_system.se_play($data_system.load_se) # Play load SE
    file = File.open('Save1.rxdata', 'rb') # Read save data
    read_save_data(file)
    file.close
    # Restore BGM and BGS
    $game_system.bgm_play($game_system.playing_bgm)
    $game_system.bgs_play($game_system.playing_bgs)
    $game_map.update # Update map (run parallel process event)
    $scene = Scene_Map.new # Switch to map screen
  end
 
  def read_save_data(file)
    characters = Marshal.load(file) # Read character data for drawing save file
    Graphics.frame_count = Marshal.load(file) # Read frame count (4 play time)
    # Read each type of game object
    $game_temp          = Game_Temp.new # Maker new Game_Temp class (bug fix)
    $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 magic number is different from when saving
    # (if editing was added with editor)
    if $game_system.magic_number != $data_system.magic_number
      $game_map.setup($game_map.map_id) # Load map
      $game_player.center($game_player.x, $game_player.y)
    end
    $game_party.refresh # Refresh party members
  end
end
 
class Scene_Menu
  def update_command
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to map screen
      $scene = Scene_Map.new
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # If command other than save or end game, and party members = 0
      if $game_party.actors.size == 0 and @command_window.index < 4
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Branch by command window cursor position
      case @command_window.index
      when 0  # item
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to item screen
        $scene = Scene_Item.new
      when 1  # skill
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 2  # equipment
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 3  # status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 4  # save
        # If saving is forbidden
        if $game_system.save_disabled
          # Play buzzer SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to save screen
        $scene = Scene_Save.new
      when 5  # end game
        # Play decision SE
        save_game_data
        $game_system.se_play($data_system.decision_se)
        # Switch to end game screen
        $scene = Scene_End.new
      end
      return
    end
  end
 
  def save_game_data
    $game_system.se_play($data_system.save_se) # Play save SE
    file = File.open('Save1.rxdata', 'wb') # Write save data
    write_save_data(file)
    file.close
    # If called from event
    if $game_temp.save_calling
      # Clear save call flag
      $game_temp.save_calling = false
      # Switch to map screen
      $scene = Scene_Map.new
      return
    end
    # Switch to menu screen
    $scene = Scene_Menu.new(4)
  end
 
  def write_save_data(file)
    # Make character data for drawing save file
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors
      characters.push([actor.character_name, actor.character_hue])
    end
    # Write character data for drawing save file
    Marshal.dump(characters, file)
    # Wrire frame count for measuring play time
    Marshal.dump(Graphics.frame_count, file)
    # Increase save count by 1
    $game_system.save_count += 1
    # Save magic number
    # (A random value will be written each time saving with editor)
    $game_system.magic_number = $data_system.magic_number
    # Write each type of game object
    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
[/rgss]

NOTES

Since it's so simple, I don't think I can be proud of it, but from time to time someone ends up asking for a script like this one. That's why I considered necessary to post it here so many more people can take a look at it and see if it fits their needs.
 
Well-written script, of course, useful for games.

But I have a few comments for you - below you will not show you which line, what commands are used so only show you this as a continuous text, received by the machine.

The first error - an error is not just a strange situation. When you click continue, produce two sounds simultaneously, one after another - first 'buzzer_se' or 'decision_se' and later 'load_se', which is generally not needed.
Ruby:
return $game_system.se_play($data_system.buzzer_se) if !@continue_enabled 

$game_system.se_play($data_system.decision_se)

$game_system.se_play($data_system.load_se)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top