Structure of CTRL scripts

Each Control script contains a main() function. This function is processed first when a CTRL script is run. The way in which scripts to graphics elements are called depends on what type of graphics object attribute the script has been written for, namely whether it is a "passive" or "active attribute.

Scripts for passive attributes

Passive attributes of a graphics element are for example its border color, its visibility, the font used etc. They are used for visualizing process states and are thus not necessarily associated with a user input. Scripts for passive attributes are run when a panel is opened, so their main() function is processed once at this time.

Example

In the following example the Control function dpConnect() is used to register the interest of the add() function in the data point attributes. Every time the online value of the data point element A or B changes, the add() function is executed.

If this script is located in a panel, the interest of the function in these points is automatically deregistered as soon as the panel is closed.

Example: Calculate C = A+B. The name of the work function is add(). The parameters passed are "A.:_online.._value" and "B.:_online.._value". The data point C is set by a dpSet() command.

main()

{

dpConnect("add", "A.:_online.._value","B.:_online.._value");

}

add(string dp1, int a, string dp2, int b)

{

dpSet("C.:_original.._value", a + b);

}

Scripts for active attributes

Active attributes are those that require a user input. Examples of such are the "when clicked" attribute that is triggered by a mouse click on the object, and attributes for the "command" fields in the attribute editor that send text input or messages from radio and check boxes. Scripts for active attributes are executed whenever the user has activated the object, i.e. clicked on it with the mouse, or entered text. The main() function is rerun each time. In general it is not necessary to register data points, although it can still be done of course.