13. Functions, defaults and return values
func total_price(price: float, count: int = 1) -> float:
return price * countfunc run() -> Array:
return [total_price(2.5), total_price(2.5, 3)]A function has a name, a parameter list and an optional return type. Default arguments make trailing parameters optional. -> void means the function does not return a value. A bare return leaves it without a result.
Use ordinary positional arguments when calling GDScript functions. An options dictionary is still one argument, even when it contains many named fields. Required parameters must come before optional ones.
PCA normally calls run when the record is run directly. If run accepts at least one parameter and no arguments were supplied, PCA passes the caller context as its first argument. The same rule applies to on_* handlers. A named utility function receives the argument array supplied by its caller.
A local called call_context or event avoids shadowing the inherited context member. Do not override an inherited helper such as Action or CallScript with an incompatible signature.
