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

asked Nov 6, 2019 in Projects by ChiCHOKEme (12 points)

1 Answer

0 votes

The property is called value not set_value:

get_node("HealthBar").value = health
answered Nov 6, 2019 by kidscancode (13,084 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

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.