Blame
|
1 | <!-- Generated from applied-computing-au vic/unit3-4/sat/C08-2026/C08-Reference-Godot by port-reference-godot-to-wiki.py — do not hand-edit; re-run the port. --> |
||||||
| 2 | # Godot Debugging Tools — GDScript |
|||||||
| 3 | ||||||||
| 4 | *The 90-second tour of what Godot gives you for debugging. For the hands-on breakpoint workflow, see [Debugging with Breakpoints in Godot](/sd/C08/Debugging%20with%20Breakpoints%20in%20Godot).* |
|||||||
| 5 | ||||||||
| 6 | **Definition.** *Debugging* is finding and fixing the errors in your program: syntax errors (won't run), logic errors (runs, but the result is wrong) and run-time errors (crashes while running). The C8-1 rubric looks for **debugging statements** at level 3–4 and **breakpoints** at level 5–6 — used on your own project, not described in the abstract. |
|||||||
| 7 | ||||||||
| 8 | ## Print debugging — the "debugging statements" |
|||||||
| 9 | ||||||||
| 10 | Everything prints to the **Output** panel at the bottom of the editor. |
|||||||
| 11 | ||||||||
| 12 | ```gdscript |
|||||||
|
13 | print("DEBUG: score = ", score) # always prints |
||||||
| 14 | print_debug("reached lock_piece()") # adds the script and line number |
|||||||
| 15 | push_warning("shape bag is empty") # yellow warning in the Debugger's Errors tab |
|||||||
| 16 | push_error("negative score!") # red error in the Errors tab (does not stop the game) |
|||||||
|
17 | ``` |
||||||
| 18 | ||||||||
|
19 |  |
||||||
| 20 | ||||||||
|
21 | A debugging statement earns its keep when it answers a question: *what value does this variable hold? did this line run at all? in what order?* Comment it out once answered — the added-then-removed print in your git history is itself debugging evidence. |
||||||
| 22 | ||||||||
| 23 | ## The Debugger panel |
|||||||
| 24 | ||||||||
|
25 | Opens at the bottom when your game hits a breakpoint or crashes on an error. Here is the whole editor at the moment a breakpoint pauses the game — the yellow arrow marks the paused line, and the Debugger panel takes over the bottom: |
||||||
| 26 | ||||||||
| 27 |  |
|||||||
|
28 | |||||||
| 29 | | Where to look | What it shows | |
|||||||
| 30 | |---|---| |
|||||||
| 31 | | **Stack Trace / Stack Frames** | which function called which — where you are and how execution got there | |
|||||||
| 32 | | **Locals** | every variable in the current function and its value *right now* | |
|||||||
| 33 | | **Breakpoints** | every red dot in your project — jump to, disable or delete them | |
|||||||
| 34 | | **Errors** | run-time errors and warnings, with clickable locations | |
|||||||
| 35 | ||||||||
|
36 | A close-up of the panel while paused — Stack Frames on the left (`check_rows` was called by `lock_piece`, and so on up the chain), Locals on the right showing `cleared`, `row` and `count` at this exact moment: |
||||||
| 37 | ||||||||
| 38 |  |
|||||||
| 39 | ||||||||
|
40 | ## Breakpoints |
||||||
| 41 | ||||||||
| 42 | Click in the gutter left of a line number — a red dot appears. Run the scene; the game pauses on that line and the Debugger opens, with **Continue**, **Step Over** and **Step Into** buttons. Breakpoints survive editor restarts, and the `breakpoint` keyword in GDScript sets one from code. Full workflow: [Debugging with Breakpoints in Godot](/sd/C08/Debugging%20with%20Breakpoints%20in%20Godot). |
|||||||
| 43 | ||||||||
| 44 | ## Two more worth knowing |
|||||||
| 45 | ||||||||
| 46 | - **Remote scene tree** — while the game runs, the Scene dock gains a **Remote** tab showing the *live* node tree; click any node to inspect (and even edit) its properties in real time. |
|||||||
| 47 | - **Debug menu** (top of the editor) — *Visible Collision Shapes* draws your collision shapes in the running game; *Synchronize Script Changes* hot-reloads script edits without restarting. |
|||||||
| 48 | ||||||||
| 49 | ## Watch |
|||||||
| 50 | ||||||||
| 51 | **Debugging Tips You MUST Know as a Godot Developer** (DevWorm, 5:27) — <https://www.youtube.com/watch?v=PB6YPnRAyjE> — advanced print statements at 02:23, breakpoints at 03:15. |
|||||||
| 52 | ||||||||
| 53 | Full detail: [Overview of debugging tools — official Godot docs](https://docs.godotengine.org/en/stable/tutorials/scripting/debug/overview_of_debugging_tools.html) |
|||||||
