How to make Health Icons properly?

Godot 4.3

Hello! I’m making health icons for my project, so when the value goes down, the icon changes. However, my code didn’t work. Does anyone know how to this properly?

CODE:

func _on_health_bar_changed():
	var min_value = 7
	var max_value = 10
	var ok_value = 6
	var min_ok_value = 3
	var bad_value = 2
	var min_bad_value = 0
	if max_value:
		anim.play("good")
	if min_value:
		anim.play("good")
	if ok_value:
		anim.play("ok")
	if min_ok_value:
		anim.play("ok")
	if bad_value:
		anim.play("bad")
	if min_bad_value:
		anim.play("bad")

Hey so I think you’re not actually comparing the health anywhere here. I also don’t think you need a min and a max variable for everything, you can just have max bad value, max ok value.

So, I’d do something like:

var max_bad_value: 2
var max_ok_value : 6

if health <= max_bad_value:
	anim.play("bad")
	return
if health <= max_ok_value:
	anim.play("ok")
	return
anim.play("good")

If it’s still not working make sure the _on_health_bar_changed is connected to the signal properly by just putting a print statement at the top of the function, or using a break point. Also check that the anim.play function is actually working (same thing use a print or break point)

4 Likes

thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.