Modify a label with a variable:

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

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?

:bust_in_silhouette: Reply From: phiz

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.

Thank you for the answer. It really helped me.

mejoresperifericos | 2020-05-17 15:39

:bust_in_silhouette: Reply From: njamster

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
:bust_in_silhouette: Reply From: ManiCus

It’s me from the future … :slight_smile:
try this:

var score = 0
signal score

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

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

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