Scope refers to the area of a program that a variable remains valid. For example if we define a variable, 'number', in the function 'func1' as follows:
then try to access that variable in another function like this:
double number_2 = number; // ERROR: number undefined
we have a problem. The problem is that a variable is not valid outside of the scope it is defined in. In the example above the "scope" is the function that it is defined in. We refer to 'number' as having "local scope" or simply refer to it as a "local variable".
If we had declared 'number' outside of 'func1', that is outside of any function, then the variable has "global scope" or is a "global variable":
double number; // global variable
number = 3.14159; // assign value to the global
double number_2 = number; // OK: number is a global
Now that's ok. Since 'number' has global scope it is "visible" to everything in the script. In fact 'number' is visible to everything including other scripts and variable's expressions in Command mode. Incidentally, variables created in messiah's Command mode are global variables themselves. These variables are not accessible through scripts because they are "static".
Static Global Variables:
We talked about static storage variables in the section Variables where we found that declaring a variable static meant that it's value would be retained between calls. Static variables have an additional meaning when we are talking about global variables. A static global variable has it's scope limited to the script it's declared in. That means that it has global scope inside that script, but it's scope is limited to that file.
static double number; // static global variable
double number_2; // non-static global variable
double tmp = foo.number; // ERROR: number is static
double tmp2 = foo.number_2; // OK: number_2 is non-static
Assume that all variables declared through messiah's Command mode are declared in a file with static storage, therefore they are inaccessible. You can of course pass their values as arguments to a script function.
|Converted from CHM to HTML with chm2web Pro 2.82 (unicode)|