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?

in Engine by (106 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):
update
score(score):

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

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

by (106 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.

by (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
by (10,423 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.
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.