$function
Create a user-defined function that can be called by $callFunction or $functionName.
Usage
$function[Function name;Param 1 (optional);Param 2...(optional)]Example
$function[printHello;name]
Hello $name
$endFunctionCall the function using $callFunction:
!!exec $function[printHello;name]
Hello $name 👋
$endFunction
$callFunction[printhello;Mika]
Hello Mika 👋
Call the function using $printHello:
!!exec $function[printHello;name]
Hello $name 👋
$endFunction
$printhello[Mika]
Hello Mika 👋
A function name can't start with number, and must be within [A-Z or a-z or _ or 0-9] for short format ($functionName)
but if you are using $callFunction to call the function, any name is valid.
Code inside the function is isolated from outside, which means changing of variables, arrays, random,...won't effect the outside.
you can access outside temporary variables (assigned by $let) but you can't change them.
Default parameter values
Parameters can have a default value by using =. The default value is used when the parameter is not provided when calling the function.
$function[greet;name=Mika]
Hello $name 👋
$endFunctionCalling the function without providing name:
$greet[]outputs:
Hello Mika 👋Providing a value overrides the default:
$greet[Alex]outputs:
Hello Alex 👋Default values can also be used with multiple parameters:
$function[greet;name=Mika;greeting=Hello]
$greeting $name 👋
$endFunctionCalling:
$greet[]outputs:
Hello Mika 👋While providing custom values:
$greet[Alex;Welcome]outputs:
Welcome Alex 👋When defining default parameter values, spaces in the parameter name are ignored, but spaces in the default value are preserved.
param=defandparam =defare equivalent.param= defis different fromparam=defbecause the spaces are part of the default value.=abcis invalid because a parameter name is required.
Function difficulty: Difficult
Tags: Function Custom Functions Nested Code