As opposed to global variables, which have a scope within the execution of a job, local variables have a scope that is limited to the compound statement where it is declared. A compound statement is a set of statements contained within curly brackets
{}, or within
begin/
end.
You must declare a local variable before any other statements in the compound statement, and you can not declare a variable more than once within the compound statement.
type name-list;
type
|
•
|
num corresponds to a numeric value, as in num($variable), and can only be assigned numeric values.
|
•
|
str corresponds to a string value, just as a global $variable. The difference is the scope.
|
|
name-list
|
Optionally, the name can be followed by one or more dimension specifications within square brackets, [], for example to declare an array variable.
|
num i, j;
str name, company, country;
num i, j, count = 3;
str name="Tom", company="OpenText";
and, begin, bool, break, case, continue, default, do, else, end, false, for, goto, if, int, not, num, return, str, struct, switch, true, while.
Compound statements of a script can be nested. A local variable is passed to all child compound statements of the compound statement where it is declared. You can re-initialize or re-declare a local variable in a child compound statement, but the variable will retain its previous state when the child compound statement goes out of scope.
Script 1 "Event" //This is the outermost compound statement type
where a local variable can exist, in this case
a "retrieved" script.
str myStr = "Hello World!"; //Outermost declaration
{ //comp. statement 1
{//comp. statement 2, nested inside if 1.
log(0, "myStr: " + myStr); // "myStr: Hello World!"
The value is passed on from
where it is declared and
initialized.
}
}
{ //comp. statement 3
str myStr = "Hello Kitty!"; //local declaration in
comp. statement 3
log(0, "myStr: " + myStr); // "myStr: Hello Kitty!"
}
log(0, "myStr: " + myStr); // "myStr: Hello World!" again,
because comp. statement 3 went
out of scope
Begin
num i, j=1;
while (i++ < 10)
log(j, "still in the loop");
End