Problems with health bar

XrayleaderXrayleader Posts: 13Member

Hello, i apologize if this isn't a proper question, but this is certainly getting on my nerves.

I have the following node setup

    -Root
    ---SingletonA
    ---Main
    -------Level
    -------HUD
    -----------Health(ControlNode)
    -----------HealthBar(Textureprogress)

And in my player script i have this signal:
self.connect("healthbar", ROUTETOHEALTH(CONTROLNODE), "_on_health_updated")

I also have this on my player script when the "hurt" routine is fired:
emit_signal("healthbar", self.hitpoints) ##self.hitpoints is updated before this part##

On the Health(ControlNode) script i have this:

    extends Control
    onready var HealthBar = $HealthBar

    func _on_health_updated(newhealth):
         HealthBar.set_value(newhealth)
         print(HealthBar.value)

According to the printed message, the health value is updated accordingly, yet, graphically, the bar never shrinks or moves, so i am wondering if i'm missing something or if i'm doing a completely wrong approach.

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 2,831Admin

    Maybe the min and max ranges on the health bar are so large that nothings appears to be happening? I don't know if that would be causing the issue, but maybe it's something to look at?

  • XrayleaderXrayleader Posts: 13Member

    min range is set to 0, max range is set to 100, so nope.
    Funny thing is, when i set value to 20 and set it to update to a higher value when hit (for testing purposes), it does update, but not when i set it to update to a lower value.

  • MegalomaniakMegalomaniak Posts: 2,748Admin

    Can we see the code updating the value, both examples - to higher and to lower?

  • XrayleaderXrayleader Posts: 13Member
    edited August 4

    Yup, here it is:

    extends Control
    onready var HealthBar = $HealthBar
    
    
    func _on_health_updated(newhealth):
         #HealthBar.set_value(newhealth)
         HealthBar.set_value(60)
         print(HealthBar.value)
    

    Then i just set the value to "10" in the editor, when the character gets hit, the bar grows accordingly

    But when i do this:

    extends Control
    onready var HealthBar = $HealthBar
    
    
    func _on_health_updated(newhealth):
         #HealthBar.set_value(newhealth)
         HealthBar.set_value(2)
         print(HealthBar.value)
    

    Nothing happens

  • MegalomaniakMegalomaniak Posts: 2,748Admin

    And what are your min and max values?

  • XrayleaderXrayleader Posts: 13Member

    0 and 100, i tried with 1 and 100 but nothing

  • TwistedTwiglegTwistedTwigleg Posts: 2,831Admin

    Are you sure the _on_health_updated signal is being sent when the value is set to 2? Maybe there is a condition or something that is preventing it from being emitted when the health is set to a low value?
    I've had times where the code that tells the UI to update was causing the issue rather than the UI itself. I have no idea if that is the case here though, but it might be something to look at if you haven't already.

  • XrayleaderXrayleader Posts: 13Member

    It does, otherwise it wouldn't print the messages confirming the value when the character is hit.

    Strangely enough, it works perfectly when set as a child of the player node rather than a child of the HUD node, which kinda grinds my gears a bit....

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file