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.

Problem with Save/Load for Auto Save & Resume script I wrote...

There's a few problems I don't know how to overcome with this script, and its been awhile since I've even had a chance to work on it so its kind of dejavu of an old topic, but I forget what the hell I was crying about back then. Anybody not familiar, I'll brief you in on what it does.

This script is supposed to save your data whenever you visit a new map (at the very end of Game_Map.setup), so whenever you decide to randomly exit the game, you'll always be able to restart at the last point on the last map you visited. You can use this as an alternative to conventional Menu-saving or Save Point systems, and have it to where the last AutoSave file is deleted when loaded.

But thats where the problem begins and ends... the data doesn't save correctly, or isn't read correctly or something. Whenever your data is loaded from the AutoSave file, it brings you to the last map but you're placed at 0x0 on that map and your player graphic is blank, bgm/bgs/weather isn't playing, etc. This basically just uses Scene_Save/Scene_Load commands to execute saving/loading the AutoSave file, I'm not sure why its not working correctly. I especially made sure that its set at the end of the setup method.

Also, I tried to make it where when Scene_Title is first called in the game, the AutoSave is loaded via Scene_Load.on_decision if the file exists before anything else happens, so its supposed to skip title and take you directly to your last map. At one point it did it, but now it just seems to maybe initialize Scene_Title twice or something, I'm not sure whats going on here either.

Here is the script, really much hasn't changed I've been too busy to script lately, otherwise I would've fixed it on my own a long time ago.

Code:
#===============================================================================
# ~** Map.AutoSaveResume **~
#-------------------------------------------------------------------------------
# Written by  : Kain Nobel
# Version     : 0.3
# Last Update : 09.24.2008
#-------------------------------------------------------------------------------
# * Description   :
#-------------------------------------------------------------------------------
#   This is an AutoSave system for the map scene. Whenever you visit a new map,
#   a file is saved within the game's Data directory. If you ever can't find a
#   save point, and want to quit a game (as long as the script is enabled), you
#   can simply close the game without saving and resume it at a later time.
#-------------------------------------------------------------------------------
# * Features      :
#-------------------------------------------------------------------------------
#   - Create an AutoSave file in the games internal directory each time visiting
#     a new map scene.
#   - Close your game and open it at a later time from the entrance of the last
#     map scene visited.
#   - Author can toggle script activity with 'AutoSave::Enabled = true/false'
#-------------------------------------------------------------------------------
# * Requirements  :
#-------------------------------------------------------------------------------
#   - SDK version 2.0 or higher, at least parts 1 and 3
#===============================================================================
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Map.AutoSaveResume', 'Kain Nobel', 0.3, '09.24.2008')
#SDK.disable('Map.AutoSaveResume') if $DEBUG
#-------------------------------------------------------------------------------
# * SDK Enabled Test - BEGIN
#-------------------------------------------------------------------------------
if SDK.enabled?('Map.AutoSaveResume')
#===============================================================================
# ~** AutoSave **~
#-------------------------------------------------------------------------------
#   This module handles all the AutoSave methods.
#===============================================================================

module AutoSave
  #-----------------------------------------------------------------------------
  # * Customizable Constant
  #-----------------------------------------------------------------------------
  Filename = "Data/AutoSaveResume"
  #-----------------------------------------------------------------------------
  # * AutoSave.save_file
  #-----------------------------------------------------------------------------
  def self.save_file
    (Scene_Save.new).on_decision(filename)
    @loaded = true
  end
  #-----------------------------------------------------------------------------
  # * AutoSave.load_file
  #-----------------------------------------------------------------------------
  def self.load_file
    (Scene_Load.new).on_decision(filename)
    @loaded = true
  end
  #-----------------------------------------------------------------------------
  # * AutoSave.filename
  #-----------------------------------------------------------------------------
  def self.filename
    filename = Filename.is_a?(String) ? Filename : "AutoSave"
    unless filename.include?('.')
      filename += '.rxdata'
    end
    return filename
  end
  #-----------------------------------------------------------------------------
  # * AutoSave.exists?
  #-----------------------------------------------------------------------------
  def self.exists?
    return FileTest.exist?(filename)
  end
  #-----------------------------------------------------------------------------
  # * AutoSave.loaded
  #-----------------------------------------------------------------------------
  def self.loaded
    @loaded = false if @loaded.nil?
    return @loaded
  end
end

#===============================================================================
# ** Game_Player
#-------------------------------------------------------------------------------
#   You encounter a bug with this script if you don't do this.
#===============================================================================

class Game_Player < Game_Character
  #-----------------------------------------------------------------------------
  # * Alias Listing
  #-----------------------------------------------------------------------------
  alias_method :autosave_game_character_encounter_count, :encounter_count
  #-----------------------------------------------------------------------------
  # * Encounter Count
  #-----------------------------------------------------------------------------
  def encounter_count
    if @encounter_count.nil?
      make_encounter_count
    end
    autosave_game_character_encounter_count
  end
end

#===============================================================================
# ** Scene_Title
#-------------------------------------------------------------------------------
#   This class has been enhanced to load an AutoSave file (if it exists) apon
# opening the Game.exe later on after previously closing a game in progress.
#===============================================================================

class Scene_Title < SDK::Scene_Base
  #-----------------------------------------------------------------------------
  # * Alias Listing
  #-----------------------------------------------------------------------------
  alias_method :autosave_scene_title_main_database, :main_database
  #-----------------------------------------------------------------------------
  # * Main Database
  #-----------------------------------------------------------------------------
  def main_database
    autosave_scene_title_main_database
    if AutoSave.exists? && !AutoSave.loaded
      AutoSave.load_file
      return
    end
  end
end

#===============================================================================
# ** Game_Map
#-------------------------------------------------------------------------------
#   Each time you visit a new map scene, the AutoSave file is written to so you
# can just close the game and open it later and start where you left off at.
#===============================================================================

class Game_Map
  #-----------------------------------------------------------------------------
  # * Alias Listing
  #-----------------------------------------------------------------------------
  alias_method :autosave_game_map_setup, :setup
  #-----------------------------------------------------------------------------
  # * Setup
  #-----------------------------------------------------------------------------
  def setup(map_id)
    autosave_game_map_setup(map_id)
    AutoSave.save_file
  end
end

#-------------------------------------------------------------------------------
# * SDK Enabled Test - END
#-------------------------------------------------------------------------------
end
 
It appears to me you are using a local variable filename which doesn't exist, when you were probably planning on using the constant Filename of which you defined at the start of your module. Your methods make use of a variable which never is defined, which would return no saved file to begin with. And then, you can't read a file that never were written as well. Makes sense, doesn't it?

Hope that does the trick.
 
Sarkilas":ydvxk9hb said:
It appears to me you are using a local variable filename which doesn't exist, when you were probably planning on using the constant Filename of which you defined at the start of your module. Your methods make use of a variable which never is defined, which would return no saved file to begin with. And then, you can't read a file that never were written as well. Makes sense, doesn't it?

Hope that does the trick.

Sarkilas: I believe he's looking for the method "filename" (lowercase) not the constant.
 
Well even when it was a constant I had this issue, but yeah the lowercase 'filename' is referring to the method. The method takes the Filename, checks if it has an extention (checks for a '.') and if it doesn't exist it tags the .rxdata onto it. If you go into the directory where the file is listed (defined in the script), then you can open the AutoSave.rxdata with Notepad and see that there is data recorded inside.

When .on_decision is called in Scene_Save or Scene_Load (or read/write_save_data), then all the $game_this and $game_that stuff is set, and its supposed to do the rest, and since I save AFTER setup I'd assume all this information is updated, but perhaps not?
 

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