Counting the lines / Get the line break's position in a text

Hello everyone! :slight_smile:

I hope someone can help me. I’m experimenting with a small game. It has a text object on the screen, where the text changes on different events by adding a new line and a sentence at the end of it.

I want to limit the size of the text, by deleting the first few lines from time to time. Some of the newly added sentences have more than one line. To do this, I want it to count the lines, or to search for the first few line breaks’ position in it.

Tried to search here and in the wiki to get some information about something similar, but I found nothing (or maybe I missed someting)

So my question is the following: Is it possible to count the lines in a text object or count the line breaks in it? Any advice would be great.

1 Like

You can search for the “NewLine()” string in the text object to get the position of the first line break, it’s a pain but you can search for the total number of line breaks with a while-loop, the idea would be:

Set variable "number_lines" = 0 Set variable "current_pos" = -1 While StrFindFrom(Text.String(), NewLine(), Variable(current_pos) + 1) != -1 : Do + 1 to variable "number_lines Do = StrFindFrom(Text.String(), NewLine(), Variable(current_pos) + 1) to variable "current_pos"
Or something like that.

Here is a simple example that just delete the first line (if there are at least two): (1.63 KB)

1 Like

Thank you very much for your help, I will try it out :slight_smile:

1 Like

I tried both of your examples. As you said, using the ‘while’ in this situation was really a painful method, so after a few experiments, I skipped the line count idea. But the example in the zip file worked perfectly.

Thanks again for your help :slight_smile:

1 Like