
25
Scripts must follow a certain format in order for the compiler to evaluate it correctly. The
example script follows this format:
•
AG Start code – auto-generated code from the wizard and a basic startup action.
•
This code must be present even if you plan on scripting all of the button functions and
generally should not be modified. This code is only displayed in the Script Editors top
window. The top window does not allow editing.
•
Constants and variables - define all your constants and global variables first. Example
constants are Source or Destination signal ID numbers, words that make your script
easier to read and write like ON- OFF, LED5, etc. Constants are fixed and never change
during run time. Variables may be local or global in scope and may be modified during
runtime.
•
Global variables are listed at the top along with constants and are “visible” anywhere in
the script.
•
Actions and Subroutines- next comes the main components of your script. It does not
matter which order you put these in but it makes sense to keep all button actions together
for readability.
•
Local variables are defined within the curly braces of an action or subroutine and are only
“visible” within that action or subroutine
Let’s look at the example code in sections.
7.6 - Example Script –Variables and Constants
The example script needs to know which switch is pressed and when to light its LED. We also
have to map the destination we want to route to and define the sources to be switched.
You seldom know all the variables your script will require when you begin, so just add them here
at the top as you go. It makes sense to group certain variables according to how they are used in
the script. This can make reading and deciphering the script easier now and when you have to edit
it a year from now!
// Custom Interlock switch code
//*************************************************************************************
*
variable //intentional error - no colon after the word variable -no variable name
constant: ON = 1
constant: OFF = 0 // Constants can be mixed in with variables as you see fit.
variable: led_num = 1
variable: switch = 0
variable: source = 0
variable: current_switch = 0
variable: last_led = 0