Variables are not declared in OptoScript because local variables (seen only within the OptoScript block) are not allowed in OptoScript. All variables are global for the strategy (we’ll talk about local variables when we get to subroutines).
If you use a variable in OptoScript code that doesn’t already exist in the strategy, you’ll receive an error message when you test compile the code (Unable to find variable or command). At that point, you can close the OptoScript editor, create the variable in PAC Control, and then go back into the editor and use it.
Variable Name Conventions
With OptoScript and in PAC Control, it’s a good idea to get into the habit of indicating the variable type in each variable’s name. Some variable types may be obvious in the name itself, but others aren’t. For more information, see “Naming Conventions” in the PAC Control User’s Guide.
Using Numeric Literals
Here are examples of how to use numeric literals in OptoScript. Formats are automatically converted if they don’t match the variable type. For example, if a value of 300.2 were assigned to an integer 32, the value would be converted to 300.
Making Assignments to Numeric Variables
Values are easily assigned to variables.
A string in OptoScript must be in double quotes. A single character can be used either as a string (in double quotes) or as an integer value representing that character in ASCII (in single quotes). When you assign a single character to a string, use double quotes to avoid a syntax error; for example: sString = "a";
To change a single-character integer into a string, use the Chr() keyword as shown:
sString = Chr('a'); n = 97;
sString = Chr(97); sString = Chr(97);
Strings can be used in the following ways:
Working with Tables
The following are examples of numeric and string tables.
For more information about data types and variables, see the PAC Control User’s Guide, Chapter 9: "Using Variables and Commands."