To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

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:

YASS
function main()

  displayIt()
  $test1 = 10
  displayIt()

end function

function displayIt()

  print($test1)

end function

function getValue()

  return 2

end function

$test1 = getValue()

The $test1 variable is defined within the global scope since it is not defined within any function definition. The main and displayIt functions reference 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 the getValue function. If it were defined before this function, the runtime would have access to the function and would throw an error.

Comments

There are no comments on this page.

New comment
Reply
Code previewClose
Feedback 👍
Comments are sent via email to me.