Label text goes out of bounds in-game.

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

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?

:bust_in_silhouette: Reply From: Gluon

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

print("Hello \n World") 

will print as

Hello
World

:bust_in_silhouette: Reply From: ponponyaya

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.

:bust_in_silhouette: Reply From: DaddyMonster

I’ll be the third person to have a crack at this. :slight_smile: 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])

printt(string)

Outputs:

0123456
7890123
4567890
1234567
89

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