Return a clear status in GDScript
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.
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()}| 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#
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.
