Difference between revisions of "UM:NetXMS Scripting Language (NXSL)"

Jump to navigation Jump to search
Line 105: Line 105:
Variables in NXSL behave the same way as variables in most popular programming languages (C, C++, etc.) do, but in NXSL you don't have to declare variables before you use them.  
Variables in NXSL behave the same way as variables in most popular programming languages (C, C++, etc.) do, but in NXSL you don't have to declare variables before you use them.  


The scope of a variable is the function within which it is defined. Any variable used inside a function is by default limited to the local function scope.  
Scope of a variable can be either global (visible in any function in the script) or local (visible only in the function within which it was defined). Any variable is by default limited to the local function scope. Variable can be declared global using '''global''' operator.


For example:
<syntaxhighlight lang="c">
x = 1;
myFunction();
sub myFunction()
{
  println "x=" . x;
}
</syntaxhighlight>
This script will cause run time error "Error 5 in line 6: Invalid operation with NULL value", because variable '''x''' is local (in implicit main function) and is not visible in function '''myFunction'''. The following script will produce expected result (prints x=1):
<syntaxhighlight lang="c">
global x = 1;
myFunction();
sub myFunction()
{
  println "x=" . x;
}
</syntaxhighlight>


= Functions =
= Functions =