How can I put text into all available place?

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

Imagine you have a scene with objects anywhere. I want to set text per code everywhere the place is available. It should look like the computer writes text automatically.

:bust_in_silhouette: Reply From: jgodfrey

What are these objects? Are they all the same kind of object? If so, I’d recommend that you place them all in some “container” node in your scene, which will make them easy to find and update via a script. For example, if all of the objects are Label nodes, you could create your scene like this:

CanvasLayer (or whatever the root node is)

Then, in a script attached to the root node, something like this:

func _ready():
    for child in $LabelContainer.get_children(): # get each child control
        if child is Label:                       # if this child is a Label...
            child.text = "your text here"	     # update it's text to whatever...


The root node is a Control. Objects are Buttons, Labels, Texturebuttons, Colorrects but with your solution I had to create many Labels by myself and that would be really hard.

MaaaxiKing | 2020-05-14 19:05

I guess it’s not clear what you’re trying to do. I though you already had the controls in your scene and you simply wanted to add text to each of them. Do the controls already exist, or does the script need to create them?

Also, you mention placing “text” everywhere, but one of the controls you metion is a ColorRect, which isn’t a text control…

Yeah, you should probably clarify what you’re trying to do…

jgodfrey | 2020-05-14 19:13

I want the created text to be a background, but possibly just where nothing else is. I have a Button att the top left corner and there shouldn’t be background because it would look like the text was cut off after the button ends. I want to have text everywhere except where my objects like Button, TextureButton, ColorRect and Labels are. At the end, it should look like a hacker is writing random characters.

MaaaxiKing | 2020-05-15 07:57