0 votes

How to modify a label with a var:
If var +1 the label = +1
Iike: if var is +1 label number "2" +1 = 3
Do you get It?

asked May 16 in Engine by ManiCus (78 points)

3 Answers

0 votes
Best answer

It's me from the future ... :)
try this:

var score = 0
signal score

func ready():
score = 0
func _proces(delta):

func update_score(score):
$label.text = str(score)

func onsignalscore(): (you have to conect de Signal with the script)
score += 1

answered 2 days ago by ManiCus (78 points)
0 votes

You can get a reference to a Node using get_node() which takes a NodePath (ultimately could be a string) so I guess you can do what you intend using get_node().

There is probably a better solution for the question you're asking, from a design perspective.

answered May 16 by phiz (94 points)

Thank you for the answer. It really helped me.

0 votes

If you want to always do this, you can use a setter-function:

var number setget set_number

func set_number(new_value):
    number = new_value
    get_node("Label").text = number
answered May 17 by njamster (8,986 points)
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.