global
variableList
VariableList is a series of one or more variable names separated by commas, each optionally followed by a data type and/or initial value:
variableName as
dataType is
initialValue
The global
keyword declares a given variable name as a global variable whose contents are available to any invocation of any handler in any object. If the variable has not already been declared or used, it is created to hold a value of the specified data type and initialized to the specified initial value. If the variable has been declared or used before, its contents remain unchanged.
Changing the value of a global variable anywhere changes its value everywhere. The global
keyword must be used in each handler or script in which the global variable is used.
The following table illustrates the four different variable scopes, global
, local
, shared
, and static
:
global |
is accessible to | any | invocation of | any | handler in | any | object |
shared |
is accessible to | any | invocation of | any | handler in | this | object |
static |
is accessible to | any | invocation of | this | handler in | this | object |
local |
is accessible to | this | invocation of | this | handler in | this | object |
The default data type if none is specified is string
. Other data types, particularly variant
, may behave in a manner incompatible with HyperTalk, but that may be desirable.
The initial value of a variable, if not specified, is empty
.
HyperTalk does not support as
or is
in the variable list. All variables in HyperTalk are implicitly declared as string
with a default value of empty
.