0 votes

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.

Godot version 3.2.3
in Engine by (20 points)

4 Answers

+1 vote

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)
by (219 points)
+1 vote

Just update the text property of the label ie

label.text = str(durability)

Do this whenever the value is changed.

by (7,152 points)
0 votes

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

by (1,051 points)
0 votes

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

https://docs.godotengine.org/en/stable/getting_started/step_by_step/signals.html#custom-signals

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