+2 votes

I've searched all over the internet and through the docs and yet still can't seem to find a way to make the label fit within a certain area. I'm adding an arrays of ints as a string to the label, and they continue expanding without making a new line, causing it to cut off the screen. Is there any way around this?

Godot version 3.4.2
in Engine by (103 points)

3 Answers

0 votes

You can use \n to create a new line for instance

print("Hello \n World") 

will print as


by (1,343 points)
0 votes

I separate your question into two small question to answer.

Q1. Find a way to make the label fit within a certain area.
This problem you can use "ScrollContainer" as Label's parent to fix it.
I mean this:
ScrollContainer(parent node)
-Label(child node)

Q2. You want Label automatically make a new line when got longer text.
To fix this problem you only need to check the property "autowrap" is true in Label Node's Inspector.

Then You got this:
imgResult Image Link

Hope this help.

by (526 points)
edited by
0 votes

I'll be the third person to have a crack at this. :) If you've got a solid string of numbers I suspect autowrap might not work. I guess you could just take the modulus if all else fails:

var array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
var line_length = 7
var string = ""

for item in array.size():
    if item and not item % line_length:
        string += "\n"
    string += str(array[item])




Or, you could loop the string rather than the array. Anyway, you get the idea hopefully.

by (1,695 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.