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.

My Custom Window script seems to mess up the F9 Debug scene...

Hey,
I was just wondering if I could get some help with my script.

I've written a script (code below) to make a custom menu show on a screen, and when an option is selected, the script changes a variable and a switch to the corresponding number using $game_variables[n] and $game_switches[n]. This all works fine - however, after I have selected an option, I return to Scene_Map.new as I should - and when I press F9, the cursor sound plays, but then the game freezes and and error comes up (see screenshot below also). The debug mode works fine before I use my script.
Thanks in advance for any help with this - it's probably a really noobish problem :)
Tigerseye

The Script:
Code:
#==============================================================================
# ** Scene_End
#------------------------------------------------------------------------------
#  This class performs game end screen processing.
#==============================================================================

class Window_SkillLearn
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make command window
    s1 = "Water"
    s2 = "Earth"
    s3 = "Air"
    s4 = "Fire"
    @choice_window = Window_Command.new(320, [s1, s2, s3, s4])
    @choice_window.x = 320 - @choice_window.width / 2
    @choice_window.y = 240 - @choice_window.height / 2
    @choice_window.back_opacity = 160
    # Create spriteset map object so that the map is displayed behind the
    # window 
    @spriteset = Spriteset_Map.new
    # 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 window
    @choice_window.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
      @spriteset.dispose
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update command window
    @choice_window.update
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Menu.new(5)
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Branch by command window cursor position
      case @choice_window.index
      when 0  # command 1
        command_0
      when 1  # command 2
        command_1
      when 2  # command 3
        command_2
      when 3  # command 4
        command_3
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Process When Choosing [0] Command
  #--------------------------------------------------------------------------
  def command_0
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Switch the Autorun Switch on
    $game_switches[28] = true
    # Change the variable value to indicate which option has been picked
    $game_variables[23] = 1
    # The rest is done with eventing
    @choice_window.active = false
    @choice_window.visible = false
    $scene = Scene_Map.new
  end
  #--------------------------------------------------------------------------
  # * Process When Choosing [1] Command
  #--------------------------------------------------------------------------
  def command_1
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Switch the Autorun Switch on
    $game_switches[28] = true
    # Change the variable value to indicate which option has been picked
    $game_variables[23] = 2
    # The rest is done with eventing
    @choice_window.active = false
    @choice_window.visible = false
    $scene = Scene_Map.new
  end
  #--------------------------------------------------------------------------
  # *  Process When Choosing [2] Command
  #--------------------------------------------------------------------------
  def command_2
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Switch the Autorun Switch on
    $game_switches[28] = true
    # Change the variable value to indicate which option has been picked
    $game_variables[23] = 3
    # The rest is done with eventing
    @choice_window.active = false
    @choice_window.visible = false
    $scene = Scene_Map.new
  end
  #--------------------------------------------------------------------------
  # *  Process When Choosing [3] Command
  #--------------------------------------------------------------------------
  def command_3
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Switch the Autorun Switch on
    $game_switches[28] = true
    # Change the variable value to indicate which option has been picked
    $game_variables[23] = 4
    # The rest is done with eventing
    @choice_window.active = false
    @choice_window.visible = false
    $scene = Scene_Map.new
  end
end

The Error:
http://www.tigerseye.uk.com/holding/error.jpg[/img]
 

poccil

Sponsor

It's a little difficult to test the problem if you don't explain how you made your custom screen appear.  I couldn't reproduce the problem.

In any case, the error isn't a Ruby error, but rather a program crash.
 
Thank you both for your prompt replies ^_^
In game, I have an event with a event-command script snippet in it (Action button), with this written:
$scene = Window_SkillLearn.new
When I go into the game I press Space / Enter to the event and the window comes up fine. I can post a demo if you think it would help.
Thanks again  :smile:
 
Okay, here we go. I assume you have RMXP's RTP?
http://holding.tigerseye.uk.com/error_recreation.zip
(If the zip doesn't work, there's also a link to the .exe file - http://holding.tigerseye.uk.com/error_recreation.exe)

Hope it downloads okay. How I get the error:
Press Enter at the chess piece - the window should come up.
Press Enter on option one (water, I think)
Now try and open the Debug screen with F9. The decision SE should sound. After a couple of seconds, the game will freeze up and the error should appear.
Thanks again,
Tigerseye
 

poccil

Sponsor

I've found the problem: you've misplaced the call to "@spriteset.dispose" in your script, which may have caused the program crash because the spriteset wasn't disposed in your script.  Here are lines 30-39 showing the correct code:

    # Prepare for transition
    Graphics.freeze
    @spriteset.dispose
    # Dispose of window
    @choice_window.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
 
Thank you so much - it works a treat ^_^ I did say it was bound to be a noobish problem :tongue: I wouldn't have found that by myself - this is my first major script :smile:
Thank you very much again,
Tigerseye
 

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