Cahnge type "Nil"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KiraArts

im trying to make a hp bar with textureprogress (for a rpg game), but in the script, when i try to change the “value” and “max_value” irecive this error: Invalid get index “maxvalue” (on base “texturepogress”) with value of typi “Nil”.
so I think I can solve it by changing the type of the variable, but i dont know how.

onready var vida_bar = $evilbar #textureprogress
onready var malovida = $evillife

var life
signal win

func _ready():

func _on_grid_atack(damage):
	life = life - damage
	evillife.text = String(life)
	if life <= 0:

func _on_grid_hpevil(hp):
	life = hp
	life_bar.value = hp
	life_bar.max_value = hp
func update_hpbar():
	vida_bar.value = vidamalo
:bust_in_silhouette: Reply From: estebanmolca

I don’t know the texture progress functions but in your code I see that you are using a declared but undefined variable: life.
Give that variable a value when declaring it e.g. life=100 and call _on_grid_hpevil() function with some value e.g. _on_grid_hpevil(100)

thanks, now it works correctly

KiraArts | 2022-08-17 21:07