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

  1. #==============================================================================
  2. # ** Scene_File
  3. #------------------------------------------------------------------------------
  4. #  This is a superclass for the save screen and load screen.
  5. #==============================================================================
  6.  
  7. class Scene_File
  8.   #--------------------------------------------------------------------------
  9.   # * Object Initialization
  10.   # help_text : text string shown in the help window
  11.   #--------------------------------------------------------------------------
  12.   def initialize(help_text)
  13. @help_text = help_text
  14.   end
  15.   #--------------------------------------------------------------------------
  16.   # * Main Processing
  17.   #--------------------------------------------------------------------------
  18.   def main
  19. # Select last file to be operated
  20. @file_index = $game_temp.last_file_index
  21. # Execute transition
  22. Graphics.transition
  23. # Main loop
  24. loop do
  25.   # Update game screen
  26.   Graphics.update
  27.   # Update input information
  28.   Input.update
  29.   # Frame update
  30.   update
  31.   # Abort loop if screen is changed
  32.   if $scene != self
  33. break
  34.   end
  35. end
  36. # Prepare for transition
  37. Graphics.freeze
  38. # Dispose of windows
  39. end
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # * Frame Update
  43.   #--------------------------------------------------------------------------
  44.   def update
  45. # If C button was pressed
  46.   on_decision(make_filename(@file_index))
  47.   $game_temp.last_file_index = @file_index
  48.   return
  49. end
  50. # If B button was pressed
  51. if Input.trigger?(Input::B)
  52.   # Call method: on_cancel (defined by the subclasses)
  53.   on_cancel
  54.   return
  55. end
  56.   #--------------------------------------------------------------------------
  57.   # * Make File Name
  58.   # file_index : save file index (0-3)
  59.   #--------------------------------------------------------------------------
  60.   def make_filename(file_index)
  61. return "Save Data.rxdata"
  62.   end
Expand to see the code.


Installation:

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

With this:
  1.  if FileTest.exist?("Save Data.rxdata")
Expand to see the code.



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

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=75204