Labels and set_text ()?

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

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.

:bust_in_silhouette: Reply From: Skipperro

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.

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

EnderCreeper1st | 2019-08-28 11:34

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

d6ta | 2020-06-26 17:40

Could you also provide the code showing what is ballCount?

Skipperro | 2020-06-26 17:45

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

d6ta | 2020-06-26 23:56

¿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.

abraham | 2020-10-02 02:12

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

Skipperro | 2020-10-02 06:55

:bust_in_silhouette: Reply From: abraham

Gracias me sirvió mucho.