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.

Help new to HUD's

HI I am trying to make my own hp/sp on screen bar outside of battle and using Yeyinde's Basic HUD Tutorial I (after putting in my own x, y cords get this error

Script 'Window_Base' line 230: NoMethodError occurred
Undefined method 'hp' for 0:fixnum

this is the line and the line after
   self.contents.font.color = actor.hp == 0 ? knockout_color :
      actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color

and this is the script I am using to make the hud
Code:
class Window_YourHUD < Window_Base
  def initialize
    super(0, 0, 100 , 100)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  def refresh
    self.contents.clear
    reset_variables
    return if !@actor
    draw_actor_hp(0, x, y)
    draw_actor_sp(0, x, y)
  end
  def reset_variables
   @actor = $game_party.actors[0]
   @old_hp = @actor ? @actor.hp : 0
   @old_maxhp = @actor ? @actor.maxhp : 0
   @old_sp = @actor ? @actor.sp : 0
   @old_maxsp = @actor ? @actor.maxsp : 0
  end
  def update
    super
    refresh if (@actor = $game_party.actors[0] or
                @old_hp = @actor ? @actor.hp : 0 or
                @old_maxhp = @actor ? @actor.maxhp : 0 or
                @old_sp = @actor ? @actor.sp : 0 or
                @old_maxsp = @actor ? @actor.maxsp : 0)
  end
end

class Scene_Map
  alias yourhud_main main
  alias yourhud_update update
  def main
    @yourhud = Window_YourHUD.new
    yourhud_main
    @yourhud.dispose
  end
  def update
    @yourhud.update
    yourhud_update
  end
end

please help me in learning how to make a HUD!!

khmp: Code in code tags please. You can delete this line when you see it.
 

khmp

Sponsor

The problem is with what you are passing into draw_actor_hp/sp. The first thing you pass into the method is the actor which you already have stored in the variable @actor. Then the x coordinate where you want to draw to on the window. The next is the y coordinate where you want to draw to on the window. In your case you get a missing method error. This is because you pass in a 0 for the actor. It wants an actor not a number.

The next parameter is the x coordinate where you want to start drawing the health. You can't just pass in "x" unless it's been defined before it's used. Like for example. In code you can do this:
Code:
x = 5
x = x + 5

But you can't do:
Code:
x = x + 5

In short you need to feed those methods actual coordinates:
Code:
draw_actor_hp(@actor, 0, 0)
draw_actor_sp(@actor, 0, 24)

If you have any further questions about it let us know.

Good luck with the scripting lukecovack! :thumb:
 
okay so now I have this
Code:
class Window_YourHUD < Window_Base
  def initialize
    super(0, 0, 155 , 70)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.size = 14
    self.opacity = 0
    refresh
  end
  def refresh
    self.contents.clear
    reset_variables
    return if !@actor
    draw_actor_hp(@actor, 0, 0)
    draw_actor_sp(@actor, 0, 15)
  end
  def reset_variables
   @actor = $game_party.actors[0]
   @old_hp = @actor ? @actor.hp : 0
   @old_maxhp = @actor ? @actor.maxhp : 0
   @old_sp = @actor ? @actor.sp : 0
   @old_maxsp = @actor ? @actor.maxsp : 0
  end
  def update
    super
    refresh if (@actor = $game_party.actors[0] or
                @old_hp = @actor ? @actor.hp : 0 or
                @old_maxhp = @actor ? @actor.maxhp : 0 or
                @old_sp = @actor ? @actor.sp : 0 or
                @old_maxsp = @actor ? @actor.maxsp : 0)
  end
end
class Scene_Map
  alias yourhud_main main
  alias yourhud_update update
  def main
    @yourhud = Window_YourHUD.new
    yourhud_main
    @yourhud.dispose
  end
  def update
    @yourhud.update
    yourhud_update
  end
end

which is cool and all but I have this gap between the top pf the screen and the hp/sp hud and the HP and SP sext are a good way away from the actual numbers generated.  I would upload a pic but not quite sure how to on these forums. How do I fix these?

khmp: Code in code tags please. You can delete this line when you see it.
 

khmp

Sponsor

Please place code in code tags lukecovack. I appreciate the spoiler but you should really put code in code tags. It's not such a problem now with the bb code smilies being harder to find but you never know. To do this, highlight the code in your post then select the button between the hyperlink(globe w/ file) and the quote(dialog bubble) button. And try not to double post. Just edit the latest post unless you are bumping.

The number placement in relationship to the two letter prefix is handled by the drawing method. There's a fourth parameter to both of those functions. The last and optional fourth parameter is called width and by default it's 144. Window_Base.draw_actor_hp has a safeguard that if you shrink the window size to or below a certain amount it cuts out drawing the maximum hp and will just display the current hp. This prevents text from drawing over text. If that missing feature doesn't bother you can append on the fourth input into the method and it will shrink the distance between "HP" and the actor's hp in number form. Like so:
Code:
draw_actor_hp(@actor, 0, 0, 100)
draw_actor_sp(@actor, 0, 16, 100)

Good luck with it lukecovack! :thumb:
 

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