0 votes

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.

in Engine by (378 points)

1 Answer

0 votes

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)
    LabelContainer
        Label1
        Label2
        Label3
        Label4

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...
by (10,892 points)

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.

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

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.

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.