Critical Error C0000005

Started by syldocaine, December 16, 2012, 05:55:46 pm

Previous topic - Next topic

syldocaine

Hi guys

First at all : I'm not the ultimate scripting pro

I have one problem with one of my scripts.
Its for enemy HP Bars and i want to show two bitmaps at the same place.One for the remaining bar and one for the empty bar.
With only one bar it works fine but when i activate the second bar,the game crashes at the end of a battle with a critical error at C000005 and a adress,dunno atm.

Can anyone help me or knows a reason for that?

Here is my script

Spoiler: ShowHide


class Window_EnemyHP < Window_Base

  def initialize(enemys)
    @enemys = enemys
    @picture = RPG::Cache.picture("hpbar.png")
    super(498, 0, 142, 190)
    self.opacity = 180
    self.contents = Bitmap.new(width - 32, height - 42)
    @pictures = RPG::Cache.picture("hpbarempty.png")
    super(498, 0, 142, 190)
    self.opacity = 180
    self.contents = Bitmap.new(width - 32, height - 42)
    refresh
  end

  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.font.size = 14
    for enemy in @enemys   
      if enemy != nil and enemy.hp > 0
        cut_X = 110 * enemy.hp / enemy.maxhp
        src_rect = Rect.new(0, 0, 110, 20)
        src_rect2 = Rect.new(0, 0, cut_X, 20)
        self.contents.blt(0, enemy.index * 38 + 8, @picture, src_rect)
        self.contents.blt(0, enemy.index * 38 + 8, @pictures, src_rect2)
        src_rect2 = Rect.new(0, 0, cut_X, 20)
        text =  enemy.name   
        #(1 + enemy.index).to_s + ". " +
        self.contents.draw_text(0, enemy.index * 38, 200, 27, text)
        text2 = "HP: " + enemy.hp.to_s + " / " + enemy.maxhp.to_s
        self.contents.draw_text(0, enemy.index * 38, 200, 56, text2)
        end 
    end 
    self.contents.font.size = 32
  end

end


#===============================================================================
# Changes at  Scene_Battle
#===============================================================================

class Scene_Battle

  def main
    # Initialize each kind of temporary battle data
    $game_temp.in_battle = true
    $game_temp.battle_turn = 0
    $game_temp.battle_event_flags.clear
    $game_temp.battle_abort = false
    $game_temp.battle_main_phase = false
    $game_temp.battleback_name = $game_map.battleback_name
    $game_temp.forcing_battler = nil
    # Initialize battle event interpreter
    $game_system.battle_interpreter.setup(nil, 0)
    # Prepare troop
    @troop_id = $game_temp.battle_troop_id
    $game_troop.setup(@troop_id)
    # Make actor command window
    s1 = $data_system.words.attack
    s2 = $data_system.words.skill
    s3 = $data_system.words.guard
    s4 = $data_system.words.item
    @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
    @actor_command_window.y = 160
    @actor_command_window.back_opacity = 160
    @actor_command_window.active = false
    @actor_command_window.visible = false
    # Make other windows
    @enemy_hp_window = Window_EnemyHP.new($game_troop.enemies)       #Changed
    @party_command_window = Window_PartyCommand.new
    @help_window = Window_Help.new
    @help_window.back_opacity = 160
    @help_window.visible = false
    @status_window = Window_BattleStatus.new
    @message_window = Window_Message.new
    # Make sprite set
    @spriteset = Spriteset_Battle.new
    # Initialize wait count
    @wait_count = 0
    # Execute transition
    if $data_system.battle_transition == ""
      Graphics.transition(20)
    else
      Graphics.transition(40, "Graphics/Transitions/" +
        $data_system.battle_transition)
    end
    # Start pre-battle phase
    start_phase1
    # 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
    # Refresh map
    $game_map.refresh
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @enemy_hp_window.dispose                                         #Changed
    @actor_command_window.dispose
    @party_command_window.dispose
    @help_window.dispose
    @status_window.dispose
    @message_window.dispose
    if @skill_window != nil
      @skill_window.dispose
    end
    if @item_window != nil
      @item_window.dispose
    end
    if @result_window != nil
      @result_window.dispose
    end
    # Dispose of sprite set
    @spriteset.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
    # If switching from battle test to any screen other than game over screen
    if $BTEST and not $scene.is_a?(Scene_Gameover)
      $scene = nil
    end
  end

  def update_phase4_step5
    # Hide help window
    @help_window.visible = false
    # Refresh status window
    @status_window.refresh
    @enemy_hp_window.refresh                                         #Changed
    # Display damage
    for target in @target_battlers
      if target.damage != nil
        target.damage_pop = true
      end
    end
    # Shift to step 6
    @phase4_step = 6
  end

end 

ThallionDarkshine

I think it's probably because you're calling super 2 times in your method.
Try this:


class Window_EnemyHP < Window_Base

  def initialize(enemys)
    super(498, 0, 142, 190)
    self.opacity = 180
    self.contents = Bitmap.new(width - 32, height - 42)
    @pictures = RPG::Cache.picture("hpbarempty.png")
    @picture = RPG::Cache.picture("hpbar.png")
    @enemys = enemys
    refresh
  end

  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.font.size = 14
    for enemy in @enemys   
      if enemy != nil and enemy.hp > 0
        cut_X = 110 * enemy.hp / enemy.maxhp
        src_rect = Rect.new(0, 0, 110, 20)
        src_rect2 = Rect.new(0, 0, cut_X, 20)
        self.contents.blt(0, enemy.index * 38 + 8, @picture, src_rect)
        self.contents.blt(0, enemy.index * 38 + 8, @pictures, src_rect2)
        src_rect2 = Rect.new(0, 0, cut_X, 20)
        text =  enemy.name   
        #(1 + enemy.index).to_s + ". " +
        self.contents.draw_text(0, enemy.index * 38, 200, 27, text)
        text2 = "HP: " + enemy.hp.to_s + " / " + enemy.maxhp.to_s
        self.contents.draw_text(0, enemy.index * 38, 200, 56, text2)
        end 
    end 
    self.contents.font.size = 32
  end

end


#===============================================================================
# Changes at  Scene_Battle
#===============================================================================

class Scene_Battle

  def main
    # Initialize each kind of temporary battle data
    $game_temp.in_battle = true
    $game_temp.battle_turn = 0
    $game_temp.battle_event_flags.clear
    $game_temp.battle_abort = false
    $game_temp.battle_main_phase = false
    $game_temp.battleback_name = $game_map.battleback_name
    $game_temp.forcing_battler = nil
    # Initialize battle event interpreter
    $game_system.battle_interpreter.setup(nil, 0)
    # Prepare troop
    @troop_id = $game_temp.battle_troop_id
    $game_troop.setup(@troop_id)
    # Make actor command window
    s1 = $data_system.words.attack
    s2 = $data_system.words.skill
    s3 = $data_system.words.guard
    s4 = $data_system.words.item
    @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
    @actor_command_window.y = 160
    @actor_command_window.back_opacity = 160
    @actor_command_window.active = false
    @actor_command_window.visible = false
    # Make other windows
    @enemy_hp_window = Window_EnemyHP.new($game_troop.enemies)       #Changed
    @party_command_window = Window_PartyCommand.new
    @help_window = Window_Help.new
    @help_window.back_opacity = 160
    @help_window.visible = false
    @status_window = Window_BattleStatus.new
    @message_window = Window_Message.new
    # Make sprite set
    @spriteset = Spriteset_Battle.new
    # Initialize wait count
    @wait_count = 0
    # Execute transition
    if $data_system.battle_transition == ""
      Graphics.transition(20)
    else
      Graphics.transition(40, "Graphics/Transitions/" +
        $data_system.battle_transition)
    end
    # Start pre-battle phase
    start_phase1
    # 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
    # Refresh map
    $game_map.refresh
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @enemy_hp_window.dispose                                         #Changed
    @actor_command_window.dispose
    @party_command_window.dispose
    @help_window.dispose
    @status_window.dispose
    @message_window.dispose
    if @skill_window != nil
      @skill_window.dispose
    end
    if @item_window != nil
      @item_window.dispose
    end
    if @result_window != nil
      @result_window.dispose
    end
    # Dispose of sprite set
    @spriteset.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
    # If switching from battle test to any screen other than game over screen
    if $BTEST and not $scene.is_a?(Scene_Gameover)
      $scene = nil
    end
  end

  def update_phase4_step5
    # Hide help window
    @help_window.visible = false
    # Refresh status window
    @status_window.refresh
    @enemy_hp_window.refresh                                         #Changed
    # Display damage
    for target in @target_battlers
      if target.damage != nil
        target.damage_pop = true
      end
    end
    # Shift to step 6
    @phase4_step = 6
  end

end 

syldocaine

Yes that was the problem.Didn't think about that.

Thx alot

ThallionDarkshine