counter of life

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

I’m making a game and I want it to have a life counter (in number) and by taking damage logically decreasing the life on the label

Do you have a question? What have you made already? If you’re stuck on some part, bec specific about what you tried and what didn’t work.

The Godot tutorial game has examples of using labels and updating them:

kidscancode | 2020-09-05 23:44

I was researching before and watching some videos and I tried set_text, but nothing changed, in that part that I crashed, because I want it to be showing life in number and when colliding with the enemy, take 1 when taking damage

CainJäger | 2020-09-06 02:36

Well, you wouldn’t use set_text(), you’d get a reference to your Label node and set its text with label_node.text = str(some_number). But again, I can’t tell you what you may or may not be doing wrong without any more information. And if you crashed, it was for a reason, and the error message is very important - it tells you what is wrong.

kidscancode | 2020-09-06 04:08

:bust_in_silhouette: Reply From: hinasis

Something like:

var life = 0
var new_label =

func _ready():
    life = 100
	new_label.text = str(life)

func do_damage(amount):
	life -= amount
	new_label.text = str(life)

I tested the label and it was in the center of the player, how can I change the label’s place to be on top of his head? and i can change color?

CainJäger | 2020-09-08 20:25