0 votes

As Im working on a Game I got a problem I cant seem to set the text of a score counter by code, (which is a label), i heard theres a Set_text() but i have no idea how to use or even set the text with it.

Additional: how to make it add a speceific number, the like text is currently 0 but when a certain function loops, it will add ex: 10 or
if bla bla:
(text) += 10

Answers in both questions are appreciated.

in Engine by (172 points)

2 Answers

+1 vote

Simple!
make a variable that is a number like:

var counter = 0

then you can change it freely, like:

counter += 10

and if you want to update the text label use:

YourLabel.text = str(counter)

YourLabel is of course your node and str function converts a number to string, which can be used with text fields.

Also, if you don't know how to get YourLabel handle, you can do this by two ways:
one:

get_node("LabelNameHere")

two:

$LabelNameHere

in both cases Godot should give you tips as you start writing.

by (207 points)

Ahh its the str thats missing in my codes haha THANKS.

i'm trying to use this in

func _process(delta):
          ## when i click and spawn a circle in
          ballCountLabel.text = str(ballCount)

but then when i run it it says
[Label:1187
and then trails off the screen? or maybe that's it, i dont know

Could you also provide the code showing what is ballCount?

I fixed it, nevermind. I stil have no idea why it showed "[Label:1187" though.

¿como lo arreglaste?
yo intento pasar la informacion de un label a otro label y tambien me pone label 1310, en lugar de poner la infomacion que tiene el otro label.

If I translated your Spanish correctly, you want to pass text from one label to another label, right?

To copy text from Label1 to Label2 you have to do something like this:

$Label2.text = $Label1.text
0 votes

Gracias me sirvió mucho.

by (18 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 Frequently asked questions and 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 [email protected] with your username.