Using the OptoScript Editor

Opening the Editor

Double-click an OptoScript block to open the editor. You can resize the editor window as needed.

OptoScript Editor2

Editor Menu Buttons

Below, is an explanation of the Editor menu buttons and the green comments shown in this example.

OptoScript Editor

Tools Tip2   Tools Tips2

Color-coded Text

When you type code in the top area, the text is color-coded:

Blue: Operators and control structures

Purple: Values

Green: Comments

– Black: Commands and names of variables, I/O points, charts, and other items

Red: String literals

To Insert a Command

1. Put your cursor in the code area where you want to insert a command.

Cursor in Editor

2. Click on the Insert Actions button in the toolbar to see a list of command groups and their commands.

Command Groups

3. Select the command group in the left-hand column, and the OptoScript command on the right-hand column.

For information on any command, highlight it and select Command Help to learn more.

Command Information

4. Click OK, and the command appears in the OptoScript code.

To Insert a Variable, Table, I/O Point, or Similar

1. Put your cursor in the code area where you want to insert a variable, table, I/O point, or similar item.

2. You can type it in exactly as you've created it, but it's recommended you use the Insert Variable button in the toolbar.

Insert Variable Tool

3. A list of all of the variable types and their names are listed.

Select the variable type on the left, and the variable name on the right, click OK, and the variable appears in your code.

Comments

Enter comments to document what the code does so that anyone who has to debug or maintain the code, can understand. 

Comments appear in green. Line comments must be preceded by two slashes.

For example:

// This is a line comment.

Block comments must be preceded by a /* and be followed by a */.

For example:

/* This is a block comment that goes 

beyond one line. */

Test Compile

When you've entered the code for an OptoScript block, click the Test Compile button in the toolbar to compile the code. The code is compiled, and the results appear in the bottom part of the OptoScript window:

Compiled Code

If there are any errors, fix them by starting with the first one listed. This is because later errors are often a result of earlier errors.

When you've finished with the code in the OptoScript block, click OK to save your work, close the editor, and return to the flowchart.

Summary

Summary

This lesson gives an overview of the OptoScript Editor in PAC Control.