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.

Weird Transfer Player Error

So, I changed a few of the Scene_Xs and Game_Xs in RPG Maker XP's script editor. I will list below what I did:

  • Scene_Menu: I only needed a simple menu my project, so I got rid of every window except the main one (@command_window). I made it so that the only options were "Go To Title" and "Nothing" (return to game).
    Scene_Map: I made a timer variable so I can have letters appear in certain messages when I want them to. I also made it so that when you press B (X or Esc), the screen tone changes to gray and when the map is renewed, it changes back to its old screen tone.
    Game_Temp: I added two new attr_accessors, a flag for an item, and the old screen tone.
    Game_Screen: I made its attr_reader "tone" into an attr_accessor.

The error I'm coming across is thus: if you return to regular gameplay from the menu (either by canceling out of it or by choosing "Nothing") and you then step on a that transfers the player, the game crashes (as in Windows prompts me to send an error report), and the computer's screen resolution doesn't reset (if the game was full-screened) until you switch to a full-screened program. Also, if you haven't viewed the script editor before loading the game, when you view it after the game closes, it shows an empty page no code rather than Game_Temp. I put a test print statement on various lines of Scene_Map to test how far the program gets before closing down, and I discovered that it gets to the line "$game_temp.transition_processing = false" in def transfer_player (the program shuts down before this is processed).

I didn't attach any code to this post because I'm not sure what I edited that could have done this and I didn't want to just throw four scripts on here. If anyone has a possible lead as to what could be causing this, I'd be more than happy to show some code.

EDIT: I've discovered that the problem is somehow connected to disposing @spriteset in Scene_Map. Normally it does dispose when changing scenes, but I stop that from happening when going to Scene_Menu because I want the game to gray out when going to the menu and recolor when returning. With that said, here's what my Scene_Map looks like:

Code:
#==============================================================================

# ** Scene_Map

#------------------------------------------------------------------------------

#  This class performs map screen processing.

#==============================================================================

 

class Scene_Map

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    $timer = 0

    $letter_by_letter = false

    # Make sprite set

    @spriteset = Spriteset_Map.new

    $game_screen.tone = $game_temp.old_tone

    # Make message window

    @message_window = Window_Message.new

    # Transition run

    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

    Graphics.freeze

    # Prepare for transition

    # Dispose of sprite set

    if !$scene.is_a?(Scene_Menu)

      @spriteset.dispose

    end

    # Dispose of message window

    @message_window.dispose

    # If switching to title screen

    if $scene.is_a?(Scene_Title)

      # Fade out screen

      Graphics.transition

      Graphics.freeze

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    #@message_window.update

    if ($timer < 2)

      $timer = $timer + 1

    else

      if ($game_temp.message_window_showing and $letter_by_letter)

        @message_window.refresh1

      end

      $timer = 0

    end

    # Loop

    loop do

      # Update map, interpreter, and player order

      # (this update order is important for when conditions are fulfilled 

      # to run any event, and the player isn't provided the opportunity to

      # move in an instant)

      $game_map.update

      $game_system.map_interpreter.update

      $game_player.update

      # Update system (timer), screen

      $game_system.update

      $game_screen.update

      # Abort loop if player isn't place moving

      unless $game_temp.player_transferring

        break

      end

      # Run place move

      transfer_player

      # Abort loop if transition processing

      if $game_temp.transition_processing

        break

      end

    end

    # Update sprite set

    @spriteset.update

    # Update message window

    @message_window.update

    # If game over

    if $game_temp.gameover

      # Switch to game over screen

      $scene = Scene_Gameover.new

      return

    end

    # If returning to title screen

    if $game_temp.to_title

      # Change to title screen

      $scene = Scene_Title.new

      return

    end

    # If transition processing

    if $game_temp.transition_processing

      # Clear transition processing flag

      $game_temp.transition_processing = false

      # Execute transition

      if $game_temp.transition_name == ""

        Graphics.transition(20)

      else

        Graphics.transition(40, "Graphics/Transitions/" +

          $game_temp.transition_name)

      end

    end

    # If showing message window

    if $game_temp.message_window_showing

      return

    end

    # If encounter list isn't empty, and encounter count is 0

    if $game_player.encounter_count == 0 and $game_map.encounter_list != []

      # If event is running or encounter is not forbidden

      unless $game_system.map_interpreter.running? or

             $game_system.encounter_disabled

        # Confirm troop

        n = rand($game_map.encounter_list.size)

        troop_id = $game_map.encounter_list[n]

        # If troop is valid

        if $data_troops[troop_id] != nil

          # Set battle calling flag

          $game_temp.battle_calling = true

          $game_temp.battle_troop_id = troop_id

          $game_temp.battle_can_escape = true

          $game_temp.battle_can_lose = false

          $game_temp.battle_proc = nil

        end

      end

    end

    # If B button was pressed

    if Input.trigger?(Input::B)

      # If event is running, or menu is not forbidden

      unless $game_system.map_interpreter.running? or

             $game_system.menu_disabled

        # Set menu calling flag or beep flag

        $game_temp.old_tone = $game_screen.tone

        $game_screen.tone = Tone.new(0, 0, 0, 255)

        @spriteset.update

        $game_temp.menu_calling = true

        $game_temp.menu_beep = true

      end

    end

    # If debug mode is ON and F9 key was pressed

    if $DEBUG and Input.press?(Input::F9)

      # Set debug calling flag

      $game_temp.debug_calling = true

    end

    # If player is not moving

    unless $game_player.moving?

      # Run calling of each screen

      if $game_temp.battle_calling

        call_battle

      elsif $game_temp.shop_calling

        call_shop

      elsif $game_temp.name_calling

        call_name

      elsif $game_temp.menu_calling

        call_menu

      elsif $game_temp.save_calling

        call_save

      elsif $game_temp.debug_calling

        call_debug

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Battle Call

  #--------------------------------------------------------------------------

  def call_battle

    # Clear battle calling flag

    $game_temp.battle_calling = false

    # Clear menu calling flag

    $game_temp.menu_calling = false

    $game_temp.menu_beep = false

    # Make encounter count

    $game_player.make_encounter_count

    # Memorize map BGM and stop BGM

    $game_temp.map_bgm = $game_system.playing_bgm

    $game_system.bgm_stop

    # Play battle start SE

    $game_system.se_play($data_system.battle_start_se)

    # Play battle BGM

    $game_system.bgm_play($game_system.battle_bgm)

    # Straighten player position

    $game_player.straighten

    # Switch to battle screen

    $scene = Scene_Battle.new

  end

  #--------------------------------------------------------------------------

  # * Shop Call

  #--------------------------------------------------------------------------

  def call_shop

    # Clear shop call flag

    $game_temp.shop_calling = false

    # Straighten player position

    $game_player.straighten

    # Switch to shop screen

    $scene = Scene_Shop.new

  end

  #--------------------------------------------------------------------------

  # * Name Input Call

  #--------------------------------------------------------------------------

  def call_name

    # Clear name input call flag

    $game_temp.name_calling = false

    # Straighten player position

    $game_player.straighten

    # Switch to name input screen

    $scene = Scene_Name.new

  end

  #--------------------------------------------------------------------------

  # * Menu Call

  #--------------------------------------------------------------------------

  def call_menu

    # Clear menu call flag

    $game_temp.menu_calling = false

    # If menu beep flag is set

    if $game_temp.menu_beep

      # Play decision SE

      $game_system.se_play($data_system.decision_se)

      # Clear menu beep flag

      $game_temp.menu_beep = false

    end

    # Straighten player position

    $game_player.straighten

    # Switch to menu screen

    $scene = Scene_Menu.new

  end

  #--------------------------------------------------------------------------

  # * Save Call

  #--------------------------------------------------------------------------

  def call_save

    # Straighten player position

    $game_player.straighten

    # Switch to save screen

    $scene = Scene_Save.new

  end

  #--------------------------------------------------------------------------

  # * Debug Call

  #--------------------------------------------------------------------------

  def call_debug

    # Clear debug call flag

    $game_temp.debug_calling = false

    # Play decision SE

    $game_system.se_play($data_system.decision_se)

    # Straighten player position

    $game_player.straighten

    # Switch to debug screen

    $scene = Scene_Debug.new

  end

  #--------------------------------------------------------------------------

  # * Player Place Move

  #--------------------------------------------------------------------------

  def transfer_player

    # Clear player place move call flag

    $game_temp.player_transferring = false

    # If move destination is different than current map

    if $game_map.map_id != $game_temp.player_new_map_id

      # Set up a new map

      $game_map.setup($game_temp.player_new_map_id)

    end

    # Set up player position

    $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)

    # Set player direction

    case $game_temp.player_new_direction

    when 2  # down

      $game_player.turn_down

    when 4  # left

      $game_player.turn_left

    when 6  # right

      $game_player.turn_right

    when 8  # up

      $game_player.turn_up

    end

    # Straighten player position

    $game_player.straighten

    # Update map (run parallel process event)

    $game_map.update

    # Remake sprite set

    @spriteset.dispose

    @spriteset = Spriteset_Map.new

    # If processing transition

    if $game_temp.transition_processing

      # Clear transition processing flag

      $game_temp.transition_processing = false

      # Execute transition

      Graphics.transition(20)

    end

    # Run automatic change for BGM and BGS set on the map

    $game_map.autoplay

    # Frame reset

    Graphics.frame_reset

    # Update input information

    Input.update

  end

end

 
 
It's always a better idea to re-show the Spriteset in Scene_Menu, as that'll work just as well. With this one, I don't know if it'll carry over correctly...

You also have some strange constructs, like this:
Code:
if $scene.is_a?(Scene_Title)

      # Fade out screen

      Graphics.transition

      Graphics.freeze

    end
You're only transitioning right if you go to the title screen, nowhere else. This means you'll have a break in consistency for shops, battles, the menu, ... This shouldn't be your bottleneck, as it's called when exiting Scene_Map, not Scene_Menu, but as you probably fondled some with Scene_Menu as well, you might have a weird construction there.

In general, switching to just initializing the Spriteset in Scene_Menu also is the preferred method, and on top of that a lot easier to implement and less failure-likely than your attempt.


Regarding the closings of the RGSS player, that's something that happened to me before once... I can't remember what I did there unfortunately, however, that's something that shouldn't normally happen (as there should always be an error raised), so I'd be happy if you could tell us what caused this when you should happen to fix it.
 
Thank you very much for your response. Just to be clear, are you saying I should make a spriteset variable for Scene_Menu and initialize it during main? Or are there more steps than that?

Also, that line of code you extracted was completely untouched from the original Scene_Map, which worked fine.

I also tried (the extremely professional method of) commenting out random lines with the word "spriteset" in it and seeing what happened (Yeah, I know you should never do that, but I didn't know what else to do). I commented out line 286 ("@spriteset.dispose"), and that seemed to fix the problem. I'm not sure why, though. Maybe it has something to do with disposing a spriteset that's already disposed?
 
Rayne Aven":2icsihcd said:
Also, that line of code you extracted was completely untouched from the original Scene_Map, which worked fine.
What can I say... XP's scripts walk strange paths... :huh:

Rayne Aven":2icsihcd said:
Thank you very much for your response. Just to be clear, are you saying I should make a spriteset variable for Scene_Menu and initialize it during main? Or are there more steps than that?
Actually, you only have to look at what Scene_Map does for @spriteset, and do everything just the same for Scene_Menu. This should mean initializing it, updating it and disposing it... however, as I was wrong before, you might double-check that... ^^"
I know that it works when you copy the exact same phrases to Scene_Menu though.

Rayne Aven":2icsihcd said:
I also tried (the extremely professional method of) commenting out random lines with the word "spriteset" in it and seeing what happened (Yeah, I know you should never do that, but I didn't know what else to do). I commented out line 286 ("@spriteset.dispose"), and that seemed to fix the problem. I'm not sure why, though. Maybe it has something to do with disposing a spriteset that's already disposed?
To clear things out, commenting-out pieces of code isn't unprofessional at all really... finding out what your program does when you take a part of it out is perfectly fine, and while on one hand, you're kind of just poking in the dark, you eventually came to a conclusion though now, didn't you? ;)

As for the disposed spriteset... it should either raise an undefined variable error, or something like 'nothing to dispose', instead of crashing the game... then again, nothing should crash the game really, so yeah... it might be that. For a matter of clearing this issue up, it might be interesting to try it out, however for your final game implementation, I strongly advise you to use the method I described after the second quote.
 
Okay, I initialized, updated, and disposed of a spriteset variable in Scene_Menu just like you said, and it works perfectly. I had to change a few things here and there (I didn't want autotiles to continue their animation while in the menu), but, yeah, it's good. So, again, thank you very much for helping me out, BlueScope.
 

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