How to flush print output?

Godot Version

v4.2.2.stable.official [15073afe3]

Question

Hi everyone,

I am trying to make an error function that prints a message before quitting. However, more often than not, no message can be seen in the console as the program quits faster than it prints. I could not make it work with some await trickery

This works fine:

func error(message: String) -> void:
	print_rich("[color=red]%s[/color]" % message)
	await get_tree().create_timer(1).timeout
	get_tree().quit(1)

func _ready():
	print("Test")
	error("Error")

This works sometimes:

func error(message: String) -> void:
	print_rich("[color=red]%s[/color]" % message)
	get_tree().quit(1)

func _ready():
	print("Test")
	error("Error")

How can I flush the output or make sure the printing is finished before quitting?

So push_error exists and I am an idiot

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.