Control Structures

on

Supported By

Syntax

on messageName parameterList
   statementList
end messageName

Description

The on keyword identifies a message handler. Message handlers are written to define your own commands or modify or redefine what happens in response to a built-in command.

When a message called messageName is sent to an object, the XION interpreter checks that object's script to see if it has a corresponding message handler also called messageName. If it does, the object responds according to that handler, and the message is sent no further (unless the script has a pass statement). If the object has no handler named messageName, the interpreter passes the message 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 message handler, if any, is accessible through the built-in function result.

The optional parameterList allows the message handler to receive some values sent along with the message. 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.

Compatibility

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.

See Also

function