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]Boss Bar Errors

Status
Not open for further replies.
http://h1.ripside.net/ScourgeDragon/Fla ... Please.jpg[/IMG]

I get this error when I try to start a new game. Strangely, This was working fine a few days ago. The only additions I've made were adding a weather script, but I've tried removing that and still nothing.

Here's the line. . .
Code:
    for i in 1..( (min / max.to_f) * width - 1)
Here's the script. . .
Code:
class Scene_Map
    
  alias raz_map_battlehud_main main
  alias raz_map_battlehud_update update
  
  def main
    @battle_switch = 1
    @enemy_hud = Enemy_HUD.new
    @enemy_hud.visible = false
    raz_map_battlehud_main
    @enemy_hud.dispose
  end
  
  def update
    @enemy_hud.update
    unless @hud_visible == true
      if $game_switches[@battle_switch]
      @enemy_hud.visible = true
      @hud_visible = true
      @hud_off = true
      end
    end
    unless @hud_off == false
      if $game_switches[@battle_switch] == false
      @enemy_hud.visible = false
      @hud_visible = false
      @hud_off = false
     end
    end
    raz_map_battlehud_update
  end
  

end

class Enemy_HUD < Window_Base
  def initialize
    super(300, 0, 340, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    @old_hp_enemy = $game_variables[ENEMYHP_VARIABLE_ID]
    refresh
  end
  
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0,100,32,"Boss")
    min = $game_variables[ENEMYHP_VARIABLE_ID] == 0 ? 1 : $game_variables[ENEMYHP_VARIABLE_ID]
    max = $game_variables[ENEMYMAXHP_VARIABLE_ID] == 0 ? 1 : $game_variables[ENEMYMAXHP_VARIABLE_ID]
    draw_slant_bar(100, 12, min, max, 200, 9, Color.new(150, 0, 0, 255), Color.new(255, 0, 0, 255))
  end
  
    def update
    super
      if @old_hp_enemy != $game_variables[ENEMYHP_VARIABLE_ID]
        refresh
       @old_hp_enemy = $game_variables[ENEMYHP_VARIABLE_ID]
    end
  end

end
class Window_Base < Window  
    #--------------------------------------------------------------------------
    # * Draw Slant Bar(by SephirothSpawn)
    #--------------------------------------------------------------------------
    def draw_slant_bar(x, y, min, max, width = 152, height = 6,
        bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
      # Draw Border
      for i in 0..height
        self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 255))
      end
      # Draw Background
      for i in 1..(height - 1)
        r = 100 * (height - i) / height + 0 * i / height
        g = 100 * (height - i) / height + 0 * i / height
        b = 100 * (height - i) / height + 0 * i / height
        a = 255 * (height - i) / height + 255 * i / height
        self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
      end
      # Draws Bar
      for i in 1..( (min / max.to_f) * width - 1)
        for j in 1..(height - 1)
          r = bar_color.red * (width - i) / width + end_color.red * i / width
          g = bar_color.green * (width - i) / width + end_color.green * i / width
          b = bar_color.blue * (width - i) / width + end_color.blue * i / width
          a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
          self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
        end
      end
    end
  end
 
What value does the variable have? Try ureplacing your script with this one:
Code:
class Scene_Map
    
  alias raz_map_battlehud_main main
  alias raz_map_battlehud_update update
  
  def main
    @battle_switch = 1
    @enemy_hud = Enemy_HUD.new
    @enemy_hud.visible = false
    raz_map_battlehud_main
    @enemy_hud.dispose
  end
  
  def update
    @enemy_hud.update
    unless @hud_visible == true
      if $game_switches[@battle_switch]
      @enemy_hud.visible = true
      @hud_visible = true
      @hud_off = true
      end
    end
    unless @hud_off == false
      if $game_switches[@battle_switch] == false
      @enemy_hud.visible = false
      @hud_visible = false
      @hud_off = false
     end
    end
    raz_map_battlehud_update
  end
  

end

class Enemy_HUD < Window_Base
  def initialize
    super(300, 0, 340, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    @old_hp_enemy = $game_variables[ENEMYHP_VARIABLE_ID]
    refresh
  end
  
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0,100,32,"Boss")
    min = $game_variables[ENEMYHP_VARIABLE_ID] <= 0 ? 1 : $game_variables[ENEMYHP_VARIABLE_ID]
    max = $game_variables[ENEMYMAXHP_VARIABLE_ID] <= 0 ? 1 : $game_variables[ENEMYMAXHP_VARIABLE_ID]
    draw_slant_bar(100, 12, min, max, 200, 9, Color.new(150, 0, 0, 255), Color.new(255, 0, 0, 255))
  end
  
    def update
    super
      if @old_hp_enemy != $game_variables[ENEMYHP_VARIABLE_ID]
        refresh
       @old_hp_enemy = $game_variables[ENEMYHP_VARIABLE_ID]
    end
  end

end
class Window_Base < Window  
    #--------------------------------------------------------------------------
    # * Draw Slant Bar(by SephirothSpawn)
    #--------------------------------------------------------------------------
    def draw_slant_bar(x, y, min, max, width = 152, height = 6,
        bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
      # Draw Border
      for i in 0..height
        self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 255))
      end
      # Draw Background
      for i in 1..(height - 1)
        r = 100 * (height - i) / height + 0 * i / height
        g = 100 * (height - i) / height + 0 * i / height
        b = 100 * (height - i) / height + 0 * i / height
        a = 255 * (height - i) / height + 255 * i / height
        self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
      end
      # Draws Bar
      for i in 1..( (min / max.to_f) * width - 1)
        for j in 1..(height - 1)
          r = bar_color.red * (width - i) / width + end_color.red * i / width
          g = bar_color.green * (width - i) / width + end_color.green * i / width
          b = bar_color.blue * (width - i) / width + end_color.blue * i / width
          a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
          self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
        end
      end
    end
  end
 
I'm still getting the same error on the same line. :(

This happens right when I start the game. So, I havn't set the variables to any number, yet. I've also tried setting the variables to the same number during the intro, but that doesn't do anything.
 
The problem is, the last operator of the range-operator can result in a float. A floating number doesn't have a succ-method and can therefore not be used to form a range. You need to convert the float to an integer.
Its best to round it to the closest integer with Float#round.

Code:
    for i in 1..( (min / max.to_f) * width - 1).round
 
Raziel: I've uploaded a demo and sent it to you by PM.

MagicMoger: I have almost no knowledge of any coding, so I don't know how I would do that. :( Would I just replace the problem line with the line you provided?
 
Sure, no problem and I didn't edit the HUD, I just used the newest version of it. ;)

This topic has been resolved. If ScourgeDragon or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
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