Topic was automatically imported from the old Question2Answer platform.
Asked By
MaximoTG98
I’m printing lots of lines in the console for my tests, but i need to clear the console when the game is running, Something like when i press X the console wipes every text i printed.
You can print an ANSI escape code that will clear the console this way:
func _ready():
print("This message won't be visible.")
clear_console()
print("The console was cleared.")
func clear_console():
var escape = PoolByteArray([0x1b]).get_string_from_ascii()
print(escape + "[2J")
Keep in mind this won’t work in the editor’s Output tab, as it doesn’t interpret ANSI escape codes. See this Stack Overflow question for more information on clearing/resetting a console using ANSI escape codes.