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.

Instant Save/Load

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!!

[rgss]#==============================================================================
# ** 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
[/rgss]

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.
 

regi

Sponsor

It's useful, nice and simple, but I'm going to comment on some coding conventions.

Please indent! It helps with readability and everything, and as it's built into the engine itself I don't know why you don't use it.

Also, it's not a big issue here (since few scripts use Scene_File) but it's generally a good idea to use alias rather than overwriting classes. This allows for greater compatibility (in case users add different scripts regarding save files).

Finally, it'd be nice to add an extra popup window to specify that you saved successfully. (I assume since there's only one file, it doesn't bother going to Scene_Save?) This way players won't be confused when they continually press Save in the menu.
 

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