Log through a GameLog autoload instead of print()

GameLog.debug() prints only in debug builds, and GameLog.warning() reports
problems such as unexpected server data or failed downloads.
This commit is contained in:
Sansan committed 2026-10-06 11:15:03 +02:00
1 parent 5cdec5cc8f
commit 5831e1e73d
20 files changed
+137 -89

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
extends Node
## Writes messages about what the game is doing, for finding problems.
##
## Registered as the [code]GameLog[/code] autoload. Use [method debug] instead of
## [code]print()[/code]: the messages show in debug builds and the editor, and are left
## out of released games. Problems the player may notice go through [method warning].
## Prints [param parts] joined together, like [code]print()[/code], in debug builds only.
func debug(...parts: Array) -> void:
if OS.is_debug_build():
print(_join(parts))
## Reports a problem in the editor's debugger and the console, in every build.
func warning(...parts: Array) -> void:
push_warning(_join(parts))
func _join(parts: Array) -> String:
return "".join(parts.map(func(part: Variant) -> String: return str(part)))