Official ZPE/YASS documentationGlobal scope
ZPE/YASS has had a global scope since a very early stage in its development. Whilst using global variables is not always very useful, there are times when they are needed.
The ZPE runtime defines a global function (known as globalFunction) that is:
- The parent of all top-level functions in code
- The parent of all global variables
- The owner of all top-level structures
The following code sample demonstrate this:
function main() displayIt() $test1 = 10 displayIt() end function function displayIt() print($test1) end function function getValue() return 2 end function $test1 = getValue()
$test1 variable is defined within the global scope since
it is not defined within any function definition. The
$test1 variable within the global scope, not within their
own scope. This means that the
$test1 variable is changed within the
global scope and not the local scope.
Notice as well, the
$test1 variable is defined after
getValue function. If it were defined before this function, the
runtime would have access to the function and would throw an error.