RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[XP][Help] Load Game in Menu (Simple Error Help)

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 85
I'll be the first to admit that I'm no scripter. But, I understand enough to attempt making minor tweaks to the system where it might be called for. Right now, I'm attempting to add a "Load" option below "Save" in the in-game pause menu. Fairly simple, right?

I've managed to get it working from the in-game menu, but I run into an "undefined method `[]' for nil:NilClass" error when I access the load game window from the title and then cancel back to the title, and I can't figure out why.

What I've done is modify Scene_Menu to include that extra menu choice (no bugs there), and when the "Load" option is selected, an in-game switch is flipped on before moving to Scene_Load. Upon hitting Cancel on the load screen, the script tests if the switch is set to true or not--if so, it returns the player to the map screen and sets it back to false. If not, then the player got there from the title screen and it goes back to Scene_Title.

Here's the chunk that's returning the error:

Code: [Select]
  #--------------------------------------------------------------------------
  # * Cancel Processing
  #--------------------------------------------------------------------------
  def on_cancel
    # Play cancel SE
    $game_system.se_play($data_system.cancel_se)
    # If called from menu
    if $game_switches[5000] == true
      # Switch to map screen
      $scene = Scene_Map.new
      $game_switches[5000] = false
      return
    else
      # Switch to title screen
      $scene = Scene_Title.new
      return
    end
  end

Specifically, the error is occurring on Line 61:

Code: [Select]
    if $game_switches[5000] == true

Here's the entire script if needed for reference:

Code: [Select]
#==============================================================================
# ** Common event in menu
#------------------------------------------------------------------------------
#  This is just a simple edit to Scene_Menu.
#==============================================================================

# The first parameter is the text that will show up in the menu
# and the second parameter is the id of the common event.

COMMON_EVENTS = [
["Journal", 1],["Party", 2],["Abilities", 18]
]

class Scene_Menu
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make command window
    s1 = $data_system.words.item
    s2 = $data_system.words.skill
    s3 = $data_system.words.equip
    s4 = "Status"
    s5 = "Save"
    s6 = "Load"
    s7 = "Quit"
    extra_menu_items = []
    COMMON_EVENTS.each do |e|
      extra_menu_items.push(e[0])
    end
    @command_window = Window_Command.new(160, [s1, s2, s3, s4] + extra_menu_items + [s5, s6])
    @command_window.index = @menu_index
    # If number of party members is 0
    if $game_party.actors.size == 0
      # Disable items, skills, equipment, and status
      @command_window.disable_item(0)
      @command_window.disable_item(1)
      @command_window.disable_item(2)
      @command_window.disable_item(3)
    end
    # If save is forbidden
    if $game_system.save_disabled
      # Disable save
      @command_window.disable_item(4)
    end
    # Make gold window
    @gold_window = Window_Gold.new
    @gold_window.x = 0
    @gold_window.y = 416
    # Make status window
    @status_window = Window_MenuStatus.new
    @status_window.x = 160
    @status_window.y = 0
    # 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
    @command_window.dispose
    @gold_window.dispose
    @status_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @command_window.update
    @gold_window.update
    @status_window.update
    # If command window is active: call update_command
    if @command_window.active
      update_command
      return
    end
    # If status window is active: call update_status
    if @status_window.active
      update_status
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when command window is active)
  #--------------------------------------------------------------------------
  def update_command
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to map screen
      $scene = Scene_Map.new
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # If command other than save or end game, and party members = 0
      if $game_party.actors.size == 0 and @command_window.index < 4
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Branch by command window cursor position
      case @command_window.index
      when 0  # item
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to item screen
        $scene = Scene_Item.new
      when 1  # skill
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 2  # equipment
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when 3  # status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
      when COMMON_EVENTS.size + 4  # save
        # If saving is forbidden
        if $game_system.save_disabled
          # Play buzzer SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to save screen
        $scene = Scene_Save.new
      when COMMON_EVENTS.size + 5  # load
        $game_switches[5000] = true
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to load screen
        $scene = Scene_Load.new
      when COMMON_EVENTS.size + 6  # end game
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to end game screen
        $scene = Scene_End.new
      else
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Set the common event to call
        $game_temp.common_event_id = COMMON_EVENTS[@command_window.index - 4][1]
        # And switch to the map
        $scene = Scene_Map.new
      end
      return
    end
  end
end


It's an existing tweak to Scene_Menu, but one that worked flawlessly and shouldn't be causing any conflicts with these kinds of modifications. It's much more likely just an issue with my syntax, but...

Any ideas on what the problem might be? Has the in-game switch handling not yet been created/defined by the title screen point of the game?
« Last Edit: April 07, 2014, 04:05:56 PM by Xelrog T. Apocalypse »

**
Rep:
Level 85
...no ideas from anyone?

*
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Rep:
Level 96
&&&&&&&&&&&&&&&&&&&&&&&&&&&
GIAW 14: 2nd Place (Hard Mode)2013 Biggest Drama Whore2013 Zero to HeroParticipant - GIAW 11Secret Santa 2013 ParticipantFor taking arms in the name of your breakfast.
I'll take a look in a bit.
&&&&&&&&&&&&&&&&

**
Rep:
Level 85
I'd appreciate it.

**
Rep:
Level 85
Guess that didn't pan out...

*
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Rep:
Level 96
&&&&&&&&&&&&&&&&&&&&&&&&&&&
GIAW 14: 2nd Place (Hard Mode)2013 Biggest Drama Whore2013 Zero to HeroParticipant - GIAW 11Secret Santa 2013 ParticipantFor taking arms in the name of your breakfast.
Sorry, still working on it. I'm used to VXA so XP is a little alien to me.
&&&&&&&&&&&&&&&&

**
Rep:
Level 85
I didn't think it was a complicated issue, but I suppose that shows my ignorance. Take your time.

...is there a way to create a temporary true/false switch within a script, rather than using in-game switches? I'm wondering if that might resolve the problem.

**
Rep:
Level 36
Scripter
I don't know if you continue needing the solution of the problem, but putting like this solved the problem for me. It can be a cooler solution, but I'm not used to XP scripting, only VX/VXA scripting so this is the best I can achieve. Here you are:

Code: [Select]
  #--------------------------------------------------------------------------
  # * Cancel Processing
  #--------------------------------------------------------------------------
  def on_cancel
    # Play cancel SE
    $game_system.se_play($data_system.cancel_se)
    # If called from menu
    if !$game_switches.nil? and $game_switches[5000] == true
      # Switch to map screen
      $scene = Scene_Map.new
      $game_switches[5000] = false
      return
    else
      # Switch to title screen
      $scene = Scene_Title.new
      return
    end
  end