So I’m trying to make a system where it adds lines of text to a TextLabel, but deletes the first line when it is full (TextBounds.Y>AbsoluteSize.Y) to make an automatic “scrolling down” effect. (You know how in the command prompt if the screen fills up with text it automatically scrolls down to make the rest of the lines visible?)
This is what I came up with:
function ShowLine(display,text)
if #display.Text==0 then --if there is no text
display.Text = text
else
display.Text = display.Text .. "\n" .. text --concatenate on next line
end
if display.TextBounds.Y > display.AbsoluteSize.Y then -- if screen is full
local _,nextLineEnd = string.find(display.Text,"\n") -- find where the first \n ends
display.Text = string.gsub(display.Text,string.sub(display.Text,1,nextLineEnd),"",1) -- remove the first line
print(nextLineEnd) -- keeps printing weird numbers
end
end
for _,text in pairs(textToPrint) do ShowLine(screen,text) wait() end
Everything works fine until the screen fills up, then although TextBounds.Y>AbsoluteSize.Y is satisfied (You can tell because print(nextLineEnd) fires), it doesn’t delete the first line and “scroll down”, and print(nextLineEnd) keeps printing 106 or 108, although the length of each line is completely different.
I’m guessing that the problem is that string.find() doesn’t exactly know where the "\n"s are located, but I don’t exactly know how I can rectify this issue.
Can somebody help? (The linked video is the current result btw)
P.S. this is my first post on the developer forum, please don’t bully me lol