Versions Compared

Key

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

Scripting Syntax

Table of Contents
maxLevel4
minLevel1
maxLevel4
include
outlinefalse
indent
excludeScripting Syntax
typelist
classprintabletrue
class

Calling Functions

A function will take in parameters and return a value. Using functions can allow the user to write a piece of code once and be able to reuse it without having to rewrite it multiple times. A function name must be called to use a function, followed by parentheses. Any arguments, if any, should be placed inside the parentheses. Using functions allows the code to retain readability and ease of maintaining the scripts. An example of how to call a script would be:

Code Block
languagejs
page.open("Introduction");

To learn more about the unique functions of Canvas, please refer to the Script and Command Function Appendix.

Semicolons

Due to using Javascript, the Canvas Script Editor will not require semicolons at the end of each line to run. However, using semicolons will increase readability and prevent unexpected behavior in the code:

Code Block
function1();
function2();

This has the same functionality and result as:

Code Block
function1()
function2()

Using semicolons will allow users to have multiple actions on one line in the Script Editor.

Code Block
function1();function2();

Declaring Variables

Variables allow the user to store specific values in them to be used later within the script. Variable names are case-sensitive, cannot have spaces, and must begin with either a letter or an underscore (_). A variable's type will be automatically determined based on what value is used to initialize it.

Variables must be called within the following formats:

Code Block
var variable; // initial value is undefined when no value
// is intialized with the declaration of the variable.

var variable1, variable2, variable3; // multiple variables
// can be declared on the same line separated by a comma.

var variable = 1; // Variables can have their value initialized
// when the variable is first declared.

Variables are local, meaning they can only be used within the script or function in which they are created. No other scripts can access variables from other scripts unless the script is imported.

Data types

Using / Setting Variables

Operators

Strings, Quotes, Escape characters

Operators, Expressions, Parentheses

Whitespace