+1 vote

Hi, I'm new to Godot and trying to understand GDScript.
I have a piece of code that changes the text of a label through a get_node("label").text assignment and then uses call_group("labels", "updateText") to, once again, change the text to another string. After that, I've used a print statemente like this:

print(groupName[0].text)

where 0 is the index of the label.
I'm a little confused because this prints the old label's text and not the one I've updated with call_group.
I've kind of concluded that this happens because "updateText()" will never execute until this first function ends, but I'm not completely sure. Is this right?

Thank you and sorry for my english.

in Engine by (13 points)

1 Answer

0 votes

Hey! random Godot citizen here, I hope I can be of some help.

If I understood correctly, what you are trying to achieve is to change the text of the labels of a certain group, if any of them is changed? Like this:

Pseudo Code:
A label's text was changed.
Update all the labels in that same group so they all have the same(or some other) text.
End of Pseudo Code

If that's the case then I could recommend using custom signals.

What really confuses me is that you are storing the labels inside the groupName[] array. How do you know which label is which? Maybe groupName[0] isn't the one you think it is, and that's why it isn't printing the correct text.

Again all of this is my guessing. Maybe if you share another example, we can provide a better solution.

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