The following table is a set of statements and functions for the script.
Type | Description | |||||
| The | |||||
| The | |||||
| The | |||||
| A
| |||||
| Only one default statement can be used in the Additionally, | |||||
| Terminates a | |||||
| A block of code designed to perform a particular task and will only executes when something calls it. | |||||
| Ends function execution and the function caller will return specifies a value. | |||||
| The | |||||
| The | |||||
| When an external program is called directly, the caller will be in standby mode until the called program (the external program) ends its operation. However, if an external program is called using |
Example for if
…else
:
In this example, if tag A
equals 1, assign 5 100 to A
. If A
equals 2Otherwise, assign 10 500 to A
. If A
does not equal 1 or 2, assign 0 to A
.
Code Block | ||
---|---|---|
| ||
A = 1; if (tag.read("A") == 1) { A = 5; } else if (A == 2) { A = 10tag.write("A", 100.0); } else { tag.write("A = 0", 500); } |
Example forwhile
:
In this example, 0 is the initial value for variable A
. When A
is less than 10, A
will increment by 1 every execution until A
equals 10. Once A
equals 10, the while
loop will endThe tag "A_WHILE" value will consistently be read and written to the variable val
in this example. If the value in the variable val
is less than 500, keep incrementing by 1 and store the incremented value to the tag "A_WHILE" in each loop. Once the variable val
equals 500, end the loop and exit the script.
Code Block | ||
---|---|---|
| ||
Avar val = 0tag.read("A_WHILE"); while (Aval < 10500) { val = val + A = A + 1;1; tag.write("A_WHILE", val) thread.msleep(10) } |
Example for do
...while
:
...
The tag "DO_VAL" value will consistently be read and written to the variable do_val
in this example. The do
...
loop will increment by 1 and store the value into the tag “DO_VAL” before executing the while
loop. Once the variable do_val
equals 200, the while
loop will terminate, but the do
statement will stay executable allowing a user to increment by 1 manually.
Code Block | ||
---|---|---|
| ||
Avar do_val = 0tag.read("DO_VAL"); do { Ado_val = Ado_val + 1; tag.write("DO_VAL", do_val) thread.msleep(100) } while (Ado_val < 10200); |
Example for for
In this example, the initial expression is 10. When i
is less than 11or equal to 100, i
will increment by 1 and store the result in A
every execution until i
equals 11100. Once i
equals 11100, the for
loop will end.
Code Block | ||
---|---|---|
| ||
var i = tag.read("FOR_VAL"); for (i = 10; i <= 11100; i = i + 1) { tag.write("FOR_VAL", A = i; i) thread.msleep(100) } |
Example for switch
…case
...
…break
The tag "PET" value will consistently be read and written to the variable pet
in this example. The switch
will start matching the values between the variable pet
and the tag "PET." If the case matches, the expression in the case will execute accordingly. When finished, the break
statement will terminate the switch
or loop altogether.
Code Block | ||
---|---|---|
| ||
var pet = tag.read("dogPET";) switch (pet) { case "cat": A = 1tag.write("CASE_STR", "I love cats too!"); break; case "dog": A = 2; break; case "hamster": A = 3tag.write("CASE_STR", "I love dogs too!"); break; } |
Example for
...
return
In this example, the string value “dog” is stored in a variable pet
. Once the switch
executes, an instruction code associated with case "dog":
will execute and store value 2 to variable A
. The return
will then act as a break to prevent the next case to execute. function
keyword calls the values in myFunction
to perform multiplication and store the results to the tag "RETURN_ONE." The return
statement then outputs the value in the tag "RETURN_ONE."
Code Block | ||
---|---|---|
| ||
petvar x = "dog"myFunction(4, 3); switchfunction myFunction(peta, b) { a = a * case "cat": A = 1; break; case "dog": A = 2; breakb; tag.write("RETURN_ONE", a); return tag.read("RETURN_ONE"); } |
Example for
...
default
In this example, when the string value “cat” is stored in a variable pet
. Once the switch
executes, an instruction code associated with case "cat":
will execute and store value 1 to variable A
. The return
will then act as a break to prevent the next case to executescript executes, the tag "REPLY" will be assigned the string value "Hello, my name is CIMON. What is your name?" by default. If the user enters their name, the "NAME" string tag will store their name. If the name entered is "Christian," the "Hi Christian!" will update the "REPLY" string tag.
Code Block | ||
---|---|---|
| ||
petvar name = tag.read("catNAME";) switch (petname) { case "catChristian": A = 1;tag.write("REPLY", "Hi Christian!") returnbreak; case "dog"default: A = 2; returntag.write("REPLY", "Hello, my name is CIMON. What is your name?"); } |
Example for
...
continue
The tag "TIMER" value will consistently be read and written to the variable timer
in this example. When the value in the variable timer
is less than 5000 and 10,000, the value in the variable timer
will be incremented by 101 each loop until it reaches 5000. When the value in the variable timer
reached 5000, the value in the variable timer
will be incremented by 1 instead. Once the value in the variable timer
reaches 10,000, the while loop will be terminated.
Code Block | ||
---|---|---|
| ||
petvar timer = tag.read("birdTIMER"); switchwhile (pettimer < 10000) { case "cat": A = timer = timer + 1; break; case "dog": tag.write("TIMER", timer); thread.msleep(100) A = 2;if (timer < 5000) { break; timer default:= timer + 100; A = 3; } |
...
In this example, 0 is the initial value for variable A
. When A
is less than 10, A
will increment by 1 every execution. If A
equals 5, the continue
statement will terminate the execution of the current iteration, then execute the next iteration in a loop. Once A
equals 10, the while
loop will end.
Code Block | ||
---|---|---|
| ||
A = 0; while (A < 10) { A = A + 1; if (A === 5) { continue; tag.write("TIMER", timer); continue; thread.msleep(100) } } |
Example forsystem.runScript()
In this example, when A
equals 0, the system.runScript()
will run the script named “NewThread function will call and executes the script name “WHILE_Script.”
Code Block | ||
---|---|---|
| ||
if (A == 0) { system.runScript("NewThreadWHILE_Script"); } |