How does exactly get_tree().call_group works?

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

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:


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.

:bust_in_silhouette: Reply From: AlbGD

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.