0 votes

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.

in Engine by (101 points)

2 Answers

+2 votes
Best answer

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.

by (10,261 points)
selected by
+1 vote

You mean the Console thing that the Debugger is attached to? There's a "CLEAR" button on the top right of that box, if the Output tab is selected.

by (197 points)

But can i clear that output using code? I need to be able to clear the output tab from the game.

hello,

did you ever figure out a way to clear the console from a script ?

thanks

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 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 webmaster@godotengine.org with your username.