Variable in label

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

I want to make a label that will display variable and if variable change it should
automatically change in label.

Example what I want to do:

You have an axe that have durability - 500 points.
If you use axe, you will get one point less so if you have 500 points and you use it five times you will have 495 points.
And I want a label that will show the durability of it.

:bust_in_silhouette: Reply From: dancaer69

I suppose you press a button to use the axe. So in on_pressed function of that button you can update the variable and set the text of the label to the updated value. Something like this:

var durability = 500

func on_button_pressed():
    durablility -= 1
    $Label.text = str(durablility)
:bust_in_silhouette: Reply From: exuin

Just update the text property of the label ie

label.text = str(durability)

Do this whenever the value is changed.

:bust_in_silhouette: Reply From: magicalogic

That can easily be done using setget. Refer to the documentation here.

:bust_in_silhouette: Reply From: wyattb

You will want to use signals to automatically change the label in your GUI without having to write to it from your logic code: