Skip to reading
GDScript Programming & Godot

Guarded calls and loop helpers

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
On this page

Breakpoint()#

Code example
Breakpoint() -> void

Reach a native GDScript breakpoint statement.

Returns: Void.

Code example
Breakpoint()

Use in an actual Godot debugging session. It is not PCA Script VM stepping.

TryCall()#

Code example
TryCall(callable: Callable, arguments: Array = [], fallback: Variant = null) -> Dictionary

Check whether a Callable is valid, then invoke it with an argument array.

Returns: Dictionary with ok, value and error.

Code example
TryCall(func(value): return value + 1, [4], 0)

An invalid Callable returns ok=false and fallback. A runtime error inside a valid Callable is not caught as an exception. The helper does not await a coroutine body.

DoWhile()#

Code example
DoWhile(body: Callable, condition: Callable, safety_limit: int = 100000) -> int

Run a Callable body at least once, then check a Callable condition after each pass.

Returns: Number of iterations.

Code example
DoWhile(func(i): print(i), func(i): return i < 3)

Body receives the zero-based index. Condition receives the incremented count. Safety limit defaults to 100000 and is clamped to at least 1. Calls are synchronous.

Page 71 of 378Permalink
Go to page