Skip to reading
Error Handling & Debugging

Return a clear status in GDScript

Edition 0.86.4.4 Hotfix 2

Updated through 0.86.4.4 Hotfix 2, with cinematic property, recorded-pose or voice-timing lessons as described in this guide. Earlier examples, screenshots and complete registry figures retain their stated edition context.

Download PDFView PDF page

LANGUAGE GUIDE · GDSCRIPT

Native GDScript can call Godot APIs. For a routine that other PCA3D languages may call, return a simple answer they can inspect without knowing anything about the native object.

Code example
func run(context: Dictionary = {}) -> Dictionary:
    var text := str(context.get("raw", "")).strip_edges()
    if not text.is_valid_int() or text.to_int() < 0:
        Warn("gate | invalid fare")
        return {"ok": false, "value": 0}
    return {"ok": true, "value": text.to_int()}
Source table from Return a clear status in GDScript, page 18
Input "bad"Warn writes a warning. The return value contains ok = false and value = 0.
Input "3"The return value contains ok = true and value = 3.
Input "0"Zero passes the rule. The ok field lets the caller distinguish a legitimate zero from an invalid entry.

What TryCall checks#

Code example
func run() -> Dictionary:
    return TryCall(Callable(), [], "no fare")

This intentionally empty Callable produced ok = false, the fallback no fare and the message Callable is invalid. TryCall tests that a callable exists before calling it. It cannot catch an arbitrary engine error inside a valid method. Check inputs and inspect a method’s own return contract.

When working in an editable Godot project, use the Godot debugger for native breakpoints and its call stack. Use the PCA3D preview to confirm the actual button, event and runtime context that reach the native code.

Page 18 of 37Permalink
Go to page