Help - Search - Members - Calendar
Full Version: Instant Save/Load
RPG RPG Revolution Forums > Scripting > Script Submissions > RGSS-Submissions
Redd
I have this awesome code I just scripted. It makes it so that when you click load or save, it automatically saves it into slot 1, the only slot, and it automatically loads from that slot also. So if you are planning on your game only having one save, then use this!!

CODE
#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
#  This is a superclass for the save screen and load screen.
#==============================================================================

class Scene_File
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     help_text : text string shown in the help window
  #--------------------------------------------------------------------------
  def initialize(help_text)
    @help_text = help_text
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Select last file to be operated
    @file_index = $game_temp.last_file_index
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # If C button was pressed
      on_decision(make_filename(@file_index))
      $game_temp.last_file_index = @file_index
      return
    end
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Call method: on_cancel (defined by the subclasses)
      on_cancel
      return
    end
  #--------------------------------------------------------------------------
  # * Make File Name
  #     file_index : save file index (0-3)
  #--------------------------------------------------------------------------
  def make_filename(file_index)
    return "Save Data.rxdata"
  end


Installation:

Just replace it with Scene_File. Oh yeah and one more thing, in Scene_Title go to line 49 and replace this:
CODE
      if FileTest.exist?("Save#{i+1}.rxdata")

With this:
CODE
      if FileTest.exist?("Save Data.rxdata")



Once again, only use this code if you are planning on having one and only one save file in your game.

If you are going to use this please credit me also. Please.
stripe103
Only one save file? That can be very handy for some. Nice!
Redd
Thanks! I kinda saw it as a bit of a downside, but it works with the project I made it for, which is a half-movie. Interactive movie, you could say.
Redd
bump. anyone wanna comment on this? took a long time to work it!
Kread-EX
This is useful for games with one save slot, like you said. You could also complete it with some kind of autoload upon Game Over. Since there's just one slot, this could be easier.
Dragons
Yes that is a very good idea Redd.
You should be able to do that if there is only 1 save slot.
quazergames
I found an error. When you try to go to "save" in the menu or use the "Call Save Screen" event, you get:

Script 'Instant Save Load' line 64: NoMethodError occured.
undefined method `on desision' for nil:NilClass

I tried to slove the problem by doing this:

CODE
#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
#  This is a superclass for the save screen and load screen.
#==============================================================================

class Scene_File
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     help_text : text string shown in the help window
  #--------------------------------------------------------------------------
  def initialize(help_text)
    @help_text = help_text
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make help window
    @help_window = Window_Help.new
    @help_window.set_text(@help_text)
    # Make save file window
    @savefile_windows = []
    for i in 0..3
      @savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))
    end
    # Select last file to be operated
    @file_index = $game_temp.last_file_index
    @savefile_windows[@file_index].selected = true
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @help_window.dispose
    for i in @savefile_windows
      i.dispose
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @help_window.update
    for i in @savefile_windows #now it says there's a problem here
      i.update
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Call method: on_decision (defined by the subclasses)
      on_decision(make_filename(@file_index)) #you forgot to include this part
      $game_temp.last_file_index = @file_index
      return
    end
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Call method: on_cancel (defined by the subclasses)
      on_cancel
      return
    end
    # If the down directional button was pressed
    if Input.repeat?(Input::DOWN)
      # If the down directional button pressed down is not a repeat,
      # or cursor position is more in front than 3
      if Input.trigger?(Input::DOWN) or @file_index < 3
        # Play cursor SE
        $game_system.se_play($data_system.cursor_se)
        # Move cursor down
        @savefile_windows[@file_index].selected = false
        @file_index = (@file_index + 1) % 4
        @savefile_windows[@file_index].selected = true
        return
      end
    end
    # If the up directional button was pressed
    if Input.repeat?(Input::UP)
      # If the up directional button pressed down is not a repeatã€
      # or cursor position is more in back than 0
      if Input.trigger?(Input::UP) or @file_index > 0
        # Play cursor SE
        $game_system.se_play($data_system.cursor_se)
        # Move cursor up
        @savefile_windows[@file_index].selected = false
        @file_index = (@file_index + 3) % 4
        @savefile_windows[@file_index].selected = true
        return
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Make File Name
  #     file_index : save file index (0-3)
  #--------------------------------------------------------------------------
  def make_filename(file_index)
    return "Save#{file_index + 1}.rxdata"
  end
end


...but now I get:

Script 'Instant Save Load' line 59: NoMethodError occured.
undefined method `each' for nil:NilClass

I have no idea what's going on.
XeroVolume
I just tested this in a new project and I don't get any errors whatsoever. It works perfectly both from the menu and from the 'Call Save Screen' Event Command. Perhaps this script is incompatible with another you are using?

First, double check that you have copied the script correctly and changed the necessary line in Scene_Title, (although that line wouldn't cause the error your getting anyway.)

If your still having problems, post the scripts you are trying to use with this one so we can have a look...
Locke
Its nice having a quick save thingy or something laugh.gif
Redd
Yeah you must change in the title and also in the menu to what was above.
Are you using any custom menu/load/save scripts quazer?
Bio Wolfz
This script looks cool, does it crash with custom save scripts?
stripe103
I think it does. I mean this script makes the game load and save directly into one file instead of the user having to choose. Most other custom save scripts does the opposite, adding more save files to save to.
Bio Wolfz
I'll test it out later, maybe you can edit any custom save so that there will be a auto save file only for the autosave.
roxie364
Can you modify this please? I really need something like this smile.gif i want to make own menu without scene_title, i want make it on scene_map. And make something like in Shining Force menu. ex: i create 4 choices, if player choose 1st - game will be save into 1st slot.. and etc... But there can be some problems with detection of loading files.. if they do not exist. (i mean - display it in game) I noob in scripts and so i can't do it ( i may just hope, what somebody can help me... And... Sorry, if my English is bad sad.gif
Redd
QUOTE (roxie364 @ Jul 1 2010, 03:04 PM) *
Can you modify this please? I really need something like this smile.gif i want to make own menu without scene_title, i want make it on scene_map. And make something like in Shining Force menu. ex: i create 4 choices, if player choose 1st - game will be save into 1st slot.. and etc... But there can be some problems with detection of loading files.. if they do not exist. (i mean - display it in game) I noob in scripts and so i can't do it ( i may just hope, what somebody can help me... And... Sorry, if my English is bad sad.gif

WRONG PLACE!!! Please post that in RGSS Suport, not in my topic!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.