This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+2 votes

I'm wondering how I would be able to get a specific line from a text in a Label with the Autowrapped feature on. The "\n" (new line) character won't appear in the String variable stored on the label (as it is autowrapping, I guess the text editing goes on the backend), so I wouldn't be able to just parse the text and reach the line that I want.

I was trying to create a way to do this, because in the project that I'm currently into, I'll need to delete the "skipped lines" (the lines in the beginning of the text that won't appear) from the label text; but there is no way to do it without a brute-force iteration on each character, searching for the one that actually separates the skipped line from the lines that are currently being printed.

The only solution I thought would be using a threshold (e.g. there is the double of skipped lines than lines that are being printed by the label), and deleting the first 30% of text; I would ALMOST be sure that the first 30% of text wouldn't happen to have one the lines that are being printed by the label, but this almost is killing me, haha.

(Using a maximum amount of characters instead of lines wouldn't work either, as characters have possibly different sizes, which would affect how many characters are in each line.)

in Engine by (313 points)

1 Answer

0 votes

I found a solution, although it isn't exactly what I was looking for.

What I did in the Text-Engine I built ( was to use the "autowrapped" feature of the Label, only to test if words would have to be clipped (an extra line would have to be added). If they have to, that I would edit the text manually to add the "\n" before the word.

I don't know how this solution works in a performance-heavy test, but all the tests that I did using it worked nicely.

by (313 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 Frequently asked questions and 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 [email protected] with your username.