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.

Loading Error

I recently added text to the Save/Load menu that displays the name of the main actor and the name of the area they are in:
Code:
class Window_SaveFile < Window_Base

 def initialize(file_index, filename)
 ...
 if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      @characters = Marshal.load(file)
      @frame_count = Marshal.load(file)
      @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_map  = Marshal.load(file)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
 ...
 end
...
 def refresh
 ...
 if @file_exist
    # Draw Actor Name
    self.contents.draw_text(60, 0, 600, 32, @game_party.actors[0].name)
    # Draw Map Name
    self.contents.draw_text(10, 32, 600, 32, $data_map_names.parent($game_map.map_id))
...

This code works for saving... but when I return (via F12) to the title screen and choose continue: every thing works fine...
BUT when I exit and reload the game... the continue on the menu does not work...
I get an error that says, "undefined method 'map_id' for nil class."

I am very perplexed by this...
 
self.contents.draw_text(10, 32, 600, 32, $data_map_names.parent($game_map.map_id))

I'm not sure where $data_map_names.parent origionates from, or how you define it... perhaps if you posted the entire script, I could test it and tell you where you went wrong.
 
$data_map_names is a class I wrote... and it's boarderline supidly simple: it takes in a map id, and returns a string hard coded into the script...

Basicly it's a
Code:
case mapID
when 1 , 2
return "Map A"
when 3 , 4, 5
return "Map B"
when 6
return "Map C"
end

And at the end of the case (if it reaches it) it just returns a blank string...  though it shouldn't reach it, as I've assinged all map IDs a name.  If you really want to see the full codeing for it, I can post it, but that same line works (as I said before) for saveing and loading after hitting F12.

For further clarfication though, this is where the object is created:
Code:
class Scene_Title
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # If battle test
    if $BTEST
      battle_test
      return
    end
    # Load database
    $data_actors        = load_data("Data/Actors.rxdata")
    $data_classes       = load_data("Data/Classes.rxdata")
    $data_skills        = load_data("Data/Skills.rxdata")
    $data_items         = load_data("Data/Items.rxdata")
    $data_weapons       = load_data("Data/Weapons.rxdata")
    $data_armors        = load_data("Data/Armors.rxdata")
    $data_enemies       = load_data("Data/Enemies.rxdata")
    $data_troops        = load_data("Data/Troops.rxdata")
    $data_states        = load_data("Data/States.rxdata")
    $data_animations    = load_data("Data/Animations.rxdata")
    $data_tilesets      = load_data("Data/Tilesets.rxdata")
    $data_common_events = load_data("Data/CommonEvents.rxdata")
    $data_system        = load_data("Data/System.rxdata")
    
    $data_map_names     = Data_MapNames.new
    
    # Make system object
...

I hope that helps describe my problem a bit more.  I've been working on it myself, but still no luck at understanding why it is not working when I try to load from the title screen when the program is first launched.
 

khmp

Sponsor

The reason you get an error is because $game_map doesn't exist when you get to Scene_Title or Scene_File. I'm actually a little confused as to how it would display anything other than a blank string when it starts or not just outright crash. As $game_map doesn't exist until a file is read from or you select "New Game". What I would recommend doing is saving the map_id in a game_variable object. These are loaded temporarily inside Window_SaveFile. Just make sure you update that variable when the map changes. While playing the game. You can have this done for you automatically if you wish with an override of a Interpreter method. Just insert an empty section above main and past in the code snippet below. Refer to the FAQ for more in depth instructions.

Code:
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
#  This interpreter runs event commands. This class is used within the
#  Game_System class and the Game_Event class.
#==============================================================================

class Interpreter
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  MAP_ID_VAR = 6
  #--------------------------------------------------------------------------
  # * Transfer Player
  #--------------------------------------------------------------------------
  def command_201
    # If in battle
    if $game_temp.in_battle
      # Continue
      return true
    end
    # If transferring player, showing message, or processing transition
    if $game_temp.player_transferring or
       $game_temp.message_window_showing or
       $game_temp.transition_processing
      # End
      return false
    end
    # Set transferring player flag
    $game_temp.player_transferring = true
    # If appointment method is [direct appointment]
    if @parameters[0] == 0
      # Set player move destination
      $game_variables[MAP_ID_VAR] =
      $game_temp.player_new_map_id = @parameters[1]
      $game_temp.player_new_x = @parameters[2]
      $game_temp.player_new_y = @parameters[3]
      $game_temp.player_new_direction = @parameters[4]
    # If appointment method is [appoint with variables]
    else
      # Set player move destination
      $game_temp.player_new_map_id = $game_variables[@parameters[1]]
      $game_temp.player_new_x = $game_variables[@parameters[2]]
      $game_temp.player_new_y = $game_variables[@parameters[3]]
      $game_temp.player_new_direction = @parameters[4]
    end
    # Advance index
    @index += 1
    # If fade is set
    if @parameters[5] == 0
      # Prepare for transition
      Graphics.freeze
      # Set transition processing flag
      $game_temp.transition_processing = true
      $game_temp.transition_name = ""
    end
    # End
    return false
  end

Alter the constant at the top called, MAP_ID_VAR to the index of whatever variable you would prefer to use. Then you can use the below statement in place of using the $game_map object.
Code:
self.contents.draw_text(10, 32, 600, 32, $data_map_names.parent(@game_variables[n]))
Where n is the index of the variable containing that saves map number.

Good luck with it Metroid386! :thumb:
 
Hm... yeah I suppose that would work, kind of mad I couldn't think of that...

I'm just a little confused about why the game_map wouldn't work.  As I *did* temperarly load game_map in the Window_SaveFile

Ah well, thanks for your help!
 

khmp

Sponsor

I didn't even notice that little addition that you made. You can try going back to the original code you had but in that case you were only messing up the scope prefix. You were using global, $, when you should have been using instance, @.

Code:
self.contents.draw_text(10, 32, 600, 32, $data_map_names.parent($game_map.map_id))
to:
Code:
self.contents.draw_text(10, 32, 600, 32, $data_map_names.parent(@game_map.map_id))

My apology for missing that :wink:

But this would also assume you altered Scene_Save and Scene_Load to save and load the Game_Map instance. I don't know how much data that would be but it would probably inflate your save files quite a bit. In any case there are a couple approaches you could take now. But I would stick with using a $game_variable object as they are already saved and loaded.

Good luck with it Metroid386! :thumb:
 
That didn't quite work (though that was definately part of it) but I think there's probably more to the problem, but oh well... I changed it to a variable anyway, thanks for looking into the old code for me though!
 

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