Watch

(Engine-Level Function)

Description: Watches its parameters and returns true when any of their values change.
Returns: Boolean
Usage: Steady State only.
Function Groups: Variable
Related to: Change | Edge | WatchArray
Format: Watch(Start[, Parm1 [, Parm2, ...])
Parameters:  
Start   
Required. Any expression which evaluates to a false (0) or true (non-0) value. This will be the initial return value of the function.
Parm1, Parm2, ...
Are any number of optional variables that are to be monitored by this function.
Comments:

This is a reset-able function whose initial return value will be set by the first parameter. This parameter is ignored after the initial evaluation of the function.
The Watch function will not be triggered by a variable whose value has been set to its existing value. That is to say, if a variable has a value of 3 and it is set in the code again to a value of 3, then there is no change and this function will not be triggered.
Only the first parameter (Start) is mandatory. Use Watch(1) to trigger a script once only on the first entry to a state.

A change in type (from 5 to "5") will also trigger the Watch.

In accordance with the VTScada Coding Standards, do not use Watch(0, ...).
Either use Watch(1, ...) or capture the values of the watched values before entering the state and check if they have changed.
Watch(0, ...) has the potential to miss a change that occurs after starting a state but before Watch(0, ...) runs.

Examples:

  If Watch(1);
  [
    ...; 
  ]

This script will be executed once only, and then the function will be reset to false (i.e. the script will not again execute unless the module, or containing state, is stopped and restarted).

  If Watch(1, Xvalue);
  [
    ...; 
  ]

This script will be executed once during the initial run-through of the state, and then again whenever Xvalue changes by any amount (unless the function is used inside a call to Latch).

Note that the behavior will differ depending on whether you use this function in a script code module or in a tag expression. In script code, the function will be reset as described, and will wait for the next trigger to occur.
In a tag expression, this function will not be reset after triggering.

Latching and Resetting Functions