I’m trying to create a rich text label that will delete its first line when it reaches 20 lines total. The code I have is as follows:
func display_Message(message):
lobbyOutput.add_text("\n" + str(message))
if lobbyOutput.get_line_count() == 20:
var firstLineEndIndex = lobbyOutput.text.find("\n")
print(str(firstLineEndIndex))
lobbyOutput.text.erase(0, firstLineEndIndex)
LobbyOutput is my rich text label. The print(str(firstLineEndIndex)) always returns -1. Is there another way to .find() a newline? Is there something that I am doing wrong? Any help is appreciated.
I think the issue here is that text isn’t representative of the internal tag stack, which has been modified by add_text. You can probably use get_parsed_text() to get that value, without bbcode.
edit: as an alternative, you could get the existing text split into lines, modify it and then assign it back to the control rather than do the modifications on the control directly (which might be more performant)
Take my 2 cents with a grain of salt, I’m new to Godot and game development.
However, I build a terminal game for a gamejam in January and ran into the same issue. What I was suggested instead is using a vbox with multiple labels, as that makes managing them a million times simpler.
I’m not sure if that suits your situation, and I’m aware it’s a workaround, rather than a solution, but perhaps it’s of use to you.