0 votes

This is function that I was using to test damage in my game where if an enemy enters the area of the player to take 10 damage off of their total health and update the texture pregress node called HealthBar
export var health: = 100

func sethealth(value):
if health == 0:
kill()
else:
health -= 10
getnode("HealthBar").setvalue = health

Whenever I run the code it has an error that says "invalid set index 'set_value' (on base: 'control') with value of type 'int'
Can someone please help me fix it
Thanks

in Engine by (12 points)

1 Answer

0 votes

The property is called value not set_value:

get_node("HealthBar").value = health
by (20,925 points)

When I run it with the:
func sethealth(value):
if health == 0:
kill()
else:
health -= 10
get_node("HealthBar").value = health
it still comes up with the error "invalid set index 'value' (on base: 'control' with value of type 'int'

It seems that "HealthBar" is a Control node, but not a TextureProgress. Therefore it doesn't have a value property.

Nevermind I fixed it, the problem seemed to be that it was a separate scene that I put in the player scene and then it refused to work but now I tried putting the texture progress directly in with the player scene and all works perfectly

thanks, i also did what you did, and it solve the problem bro.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.