Toggle

(Engine-Level Function)

Description: Returns its previous status value except when its parameter changes from a false to a true, in which case it changes its value.
Returns: Boolean
Usage: Steady State only.
Function Groups: Variable
Related to: Latch
Format:  Toggle(X)
Parameters:  
X
Required. Any numeric expression giving the status value to use to cause the function value to change state.
Comments: This function starts in a state with its return value being the same as its parameter. If the parameter X changes from an in valid value to a valid false, the return value will be 0. If the parameter X changes from an invalid value to a valid true, the return value will be 1.
This function resets its parameters after they evaluate to true. This is significant only for functions which can be reset such as MatchKeys, TimeOut, Intgr and RTimeOut.

Example:

on = Toggle(MatchKeys(2, "A"));

The variable on begins set to 0. Pressing the "A" key will change it to 1; pressing "A" again will change it back to 0. Pressing "A" a third time will change it to 1 again, and so on.

Latching and Resetting Functions