function
functionName parameterList
statementList
end
functionName
The function
keyword identifies a function handler. Function handlers are written to define your own functions. Functions defined with function handlers must be called using parentheses rather than the the
, of
, or in
keywords.
When a function called functionName is evaluated, the XION interpreter checks the script of the topmost object in the hierarchy to see if it has a corresponding function handler also called functionName. If it does, the function handler executes, and the function call is sent no further (unless the script has a pass
statement). If the object has no handler named functionName, the interpreter passes the function call to the next object in the hierarchy.
The statements in a handler execute until an end
, exit
, pass
, return
, or throw
keyword is reached. The return value of a function handler becomes the value of the function where the function was originally called.
The optional parameterList allows the function handler to receive some values sent along with the function call. This list is a series of local variable names separated by commas, each optionally followed by a data type and/or default value:
variableName as
dataType is
defaultValue
When the handler executes, each value is put into the parameter variable that appears in the corresponding position. If no value is specified for a parameter variable, the default value for that parameter variable (or empty
if no default value is specified) is put into that parameter variable.
The default data type of a parameter if none is specified is string
. Other data types, particularly variant
, may behave in a manner incompatible with HyperTalk, but that may be desirable.
User-defined functions are always followed by parentheses. Unlike built-in functions, user-defined functions cannot be called with the
, of
, or in
.
HyperTalk does not support as
or is
in the parameter list. All parameter variables in HyperTalk are implicitly declared as string
with a default value of empty
.
In HyperTalk, handlers may not be nested; that is, a handler may not appear in the middle of another handler. In OpenXION, handlers can be nested. The nested handlers will only be accessible from within the handler in which they appear.