new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Godot 4 Patterns · all subjects

debugging

14 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Print output for arrays and dicts

print(arr) outputs [a, b, c]. print(dict) outputs {a:1, b:2}. For pretty-printed output, use JSON.stringify(d, " ").

UNTYPED_DECLARATION diagnosis: find := with Variant right side

When UNTYPED_DECLARATION appears in Errors: locate the file and line, look for := where the right side is dict[k], arr[i], dict.get(...), or json.data, then replace with explicit type: var x: Type = ...

UNSAFE_CALL_ARGUMENT diagnosis: casting Variant to function parameter

UNSAFE_CALL_ARGUMENT occurs when passing a Variant to a function expecting a typed parameter. Cast the argument: func_name(str(variant_arg)), int(...), or float(...).

UNSAFE_PROPERTY_ACCESS diagnosis: accessing property on untyped value

UNSAFE_PROPERTY_ACCESS happens when accessing .property on a Variant or supertype. Cast first: var typed: SubType = my_var; typed.property.

Debug input events: print key and mouse info to Output panel

To debug input issues, print event details: for InputEventKey print keycode, pressed, echo; for InputEventMouseButton print button_index, pressed. Check the Output panel to confirm events arrive.

Testing pure logic with headless Godot

Write unit tests for pure logic classes in test files that extend SceneTree. Run with 'godot --headless --script tests/test_parser.gd' from CLI. Add to CI for regression testing. This works because logic classes have no Node dependencies.

Debug diagnostic order (cheapest first)

When diagnosing Godot runtime issues, follow this order: (1) Read the Output panel at the bottom of editor, where all prints and errors appear. (2) Check the Errors panel (next to Output) for yellow warnings and red errors. (3) Add prints to suspect code paths. (4) Set breakpoints (F9 in script editor on a line) then run. (5) Check the Inspector in the remote scene tree to see live state while the game is running.

Strategic print logging with identifying tags

Use identifying tags in print statements to make logs searchable and context-clear. Examples: print("[Splash] _ready called"), print("[Parser] tokens=%s" % [tokens]), print("[Save] writing slot %d to %s" % [slot, path]). Use printerr() for non-fatal errors that should stand out in red. Use push_error("...") for errors that should appear in the Errors panel. Use push_warning("...") for soft issues.

Conditional debug output with DEBUG constant

Define const DEBUG: bool = OS.is_debug_build() at the top of script. This evaluates to true when running from editor and false in release builds. Wrap heavy debug output in if DEBUG: blocks so release builds do not print, avoiding performance and privacy issues.

Breakpoint workflow in Godot 4 editor

To set a breakpoint: (1) Open the script in the editor. (2) Click on the gutter (line number area); a red dot appears. (3) Run with F5 or F6 (current scene). (4) When the line is hit, the game pauses. (5) Inspect locals and globals in the bottom panel. (6) F11 steps into, F10 steps over, F12 continues execution.

Print function variants and output styling

print("hello") outputs standard with newline. printraw("no newline") outputs without newline. printerr("ERROR!") outputs in red. print_rich("[b]bold[/b]") supports BBCode formatting. push_error("xxx") appears in the Errors panel as an error. push_warning("xxx") appears in the Errors panel as a warning.

Debug silent game crash via terminal

If the game crashes silently and the window closes: (1) Run from terminal: /path/to/Godot --path /path/to/project. (2) Watch terminal output for the actual crash message. (3) Check ~/.config/godot/ (Linux/Mac) for crash reports. These locations hold the details that the editor Output panel does not display.

Common silent failure symptoms and causes

Click does nothing: likely mouse_filter or focus issue. Type once then cannot type again: LineEdit lost focus. Splash does not transition: Tween or Timer not firing, or target scene has parse error. Save not loading: JSON parse error (check format). NPC does not appear: Scene visible=false somewhere up the tree. Audio not playing: Bus muted, file path wrong, or AudioStreamPlayer not in tree. Signal handler not called: Signal disconnected when node was freed.

Reproduction steps template for fast debugging

When diagnosing or asking for help, document steps in this format: (1) list numbered reproduction steps to reach the failure. (2) State the expected outcome. (3) State the actual outcome. (4) Show the Errors panel contents. (5) Show the Output panel contents with timestamps and tagged prints. Example: # Reproduction: 1. Open project. 2. Press F5. 3. Click "Войти в игру". 4. Type "go north" + Enter ← FAILS HERE. # Expected: Move to living room. # Actual: Cursor disappears. # Errors panel: [empty]. # Output panel: [Splash] _ready...

Give your agent this brain