Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Comments

Users can insert comments anywhere in a script. Comments are not executed like regular code. Instead, they can be used for documentation or temporarily disable blocks of code.

...

Code Block
languagejs
// This is a single-line comment
/* This is a
 * multi-line
 * comment.*/

Calling Functions

A function takes in some parameters and returns a value. Functions let you re-use pieces of code without re-writing everything.

...

For example, tag.write takes two arguments. The first is the tag name, and the second is the value to write. The script below writes the value 1 to the tag called "my_tag":

tag.write("my_tag", 1);

Declaring Variables

Variables let you store values and access them later in the script.

...

Variables must be declared before they can be used in the script. Variables declared in a separate script cannot be used unless you first import that script using system.importScript.

Using and Setting Variables

Once a variable has been declared, you can assign a new value to it using the assignment operator =. For example:

...

Code Block
tag.write("my_tag", 1);

Operators and Parentheses

You can add, subtract, multiply, and use other operators on variables and other values. See the “Operators” section for more information.

...

Code Block
add(1, 2)         // 3
add(add(1, 2), 3) // 6

Reading and Writing Tag Values

To get a tag’s current value, use tag.read. This takes in one argument, which is the name of the tag, and returns the tag’s value.

To write a tag value, use tag.write. This takes in two arguments: the name of the tag and the value to write. There is no return value.

...

You must call tag.write each time you want to update a tag value, and you must call tag.read each time you want to use the latest tag value. When used in a loop, it is recommended to use tag.read at the beginning of the loop and to use tag.write at the end of the loop.

Semicolons

JavaScript uses semicolons to indicate the end of expressions. Using semicolons at the end of lines is not required, but is recommended for better organization and clarity:

...

Code Block
some_function();some_other_function;

Whitespace

JavaScript ignores whitespace characters like spaces, tabs, and line breaks.

...