Important note: all examples follow aTbRef naming conventions.
Calling functions from action code
Regardless of where stored, every function in the current document can be called from any action.
If a function has arguments, the caller must supply values for each argument, even if only as an empty string (or other default data-type value. Extra arguments are ignored. If a function is redefined, the most recent definition replaces any existing definitions.
If the called function returns a value, then the calling code needs to use an attribute or variable to receive that value.
Examples—with a return value
Calling a single literal value for an argument:
$MyNumber = fAddTax(500);
Calling a function with a single argument:
$Text = fMakeTable($CategoryList);
Calling a function with multiple arguments, that returns List-type data (see here for multi-value returns):
$MyList = fAlterList($CategoryList,$SomeString,"alternate");
A function with no arguments:
$MyNumber = fCheckSum();
Notice how in every case the function is called as the right side of an '=' (i.e. value assignment) operation so the return value can be stored and further used.
Example—with no return value
A function with no return value:
fReset();
Note in this case that whilst no left-side recipient is needed but function parentheses must be included.
Can a function call another function?
Yes. A function can call itself. This is called 'self-reference', and is an advanced technique that should be used with caution and tested in a test document before use at scale. This process is also known as recursion.
Next: Variable use in functions