10. Functions and parameters
function total_price(price: number, count: integer = 1): number
return price * count
endfunction run()
let one = total_price(2.5)
let three = total_price(2.5, 3)
return [one, three]
endA function packages a job under a name. Parameters are inputs. The returned value is its output. A default value makes the last parameter optional. Calls to ordinary functions use positional arguments in the declared order.
Declare functions at the top level, not inside another function. Use function run() as the normal entry point when the record is called directly. A script can also contain top-level instructions, but when run exists the default call selects that function. Keep initialization in declarations and the actual job in run to avoid ambiguity.
A function can call another function, including itself, but the runtime limits nested calls to 64. A loop is usually better than recursion for walking a list of inventory items. Type annotations describe supported value types; they do not turn a function into an exposed visual node by themselves.
Figure 4. Small named functions keep puzzle checks separate from the response that uses them.
