scope
The
scope of an
identifier is the region of a
script's source
code where the identifier may be accessed. If the identifier is defined outside of a
state or
user-defined function it has a
global scope, and it may be accessed anywhere within any of the script (after the definition). If the identifier is defined inside a state, or a user-defined function, or an
event handler, then the scope is
local to that containing context, and it may not be used outside of that context.
// local
default
{
state_entry()
{
integer gNum = 6;
// gNum == 6
}
touch_start(integer num_detected)
{
// gNum not defined
}
}
|
// global
integer gNum = 6;
default
{
state_entry()
{
// gNum == 6
}
touch_start(integer num_detected)
{
// gNum == 6
}
} |
Script |
Code |
Global |
Local |
Declare