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.

[Resolved] Menu script error

Status
Not open for further replies.
Problem: Game crashes when I open the menu the second time.

I can open my custem menu once and every thing is ok but the second time I open it the game crashes.  No Errors

The script.
Code:
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs menu screen processing.
#==============================================================================
class Scene_Menu
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     menu_index : command cursor's initial position
  #--------------------------------------------------------------------------
  def initialize(menu_index = 0)
    @menu_index = menu_index
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    @spritesetmap = Spriteset_Map.new
    # Make command window
    s1 = "New Tattie"
    s2 = "Random Tattie"
    s3 = "Save Tattie"
    s4 = "Load Tattie"
    s5 = "Name Tattie"
    s6 = "Exit Menu"
    s7 = "Exit Game"
    @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6, s7])
    @command_window.index = @menu_index
    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
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @command_window.update
    # If command window is active: call update_command
    if @command_window.active
      update_command
      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
        $game_temp.common_event_id = 1
        $scene = Scene_Map.new
      when 1  # skill
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $game_temp.common_event_id = 2
        $scene = Scene_Map.new
      when 2  # equipment
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $scene = Scene_Save.new
      when 3  # status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $loadp = 1
        $scene = Scene_Load.new
      when 4  # Party
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $scene = Scene_Name.new
          when 5  # Common Event
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $scene = Scene_Map.new
      when 6  # save
        $scene = Scene_End.new
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when status window is active)
  #--------------------------------------------------------------------------
  def update_status
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Make command window active
      @command_window.active = true
      @status_window.active = false
      @status_window.index = -1
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # 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
        $game_temp.common_event_id = 1
        $scene = Scene_Map.new
      when 1  # skill
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $game_temp.common_event_id = 2
        $scene = Scene_Map.new        
      when 2  # equipment
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $scene = Scene_Save.new
      when 3  # status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $scene = Scene_Load.new
      when 4  # Party
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $scene = Scene_Name.new
      when 5  # Common Event
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $scene = Scene_Map.new
      when 6  # save
        $scene = Scene_End.new
      end
      return
    end
  end
end
 
Well, it doesn't crash after I open and close it several times.
Are you trying to create and later modify this script? It looks like you don't know how to modify it, yet.
You may need to take a look at the default menu script and see if you find what did you change in the code that makes the game crash.
Actually you can start from scratch and test the script every single time you modified it. I mean, you may test if it works right after you change or add an option to the menu.
 
Here is a list of the scripts i'm using.
SDK V2.3
Mouse System
Code:
#----------------------------------------------------------------------------
#Credits: This is an adaptation from a script created by shun ([url=http://simp.nobody.jp/]http://simp.nobody.jp/[/url])
#Also looked at Cybersam's work and Astro_mech and Mr.Mo's mouse script edits to 
#learn how onmouse events work.
#----------------------------------------------------------------------------
# TO USE:
# In each map event, put the name of the cursor you want to show as a comment.
# The comment must be the first event command. Make sure that you put the cursor
# in your Icons directory (name in comment and icon name must match exactly)
#----------------------------------------------------------------------------


module Input
  #--------------------------------------------------------------------------
  # â—
 
Status
Not open for further replies.

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