Sequences
There is another type of flow control statement that the CMS recognizes,
that of the "SEQUENCE". A sequence begins with the word "SEQUENCE" and ends
with the word "ENDSEQUENCE". These are unique in that they allow a sequence of
events, essentially an independent piece of script, to be executed within
the main script itself. The sequence will execute on each loop through the
script and work its way along towards the end of the sequence as whatever
conditions it's set to require are met.
When the sequence reaches a point
where it can go no further on this loop, perhaps it needs to wait for a
button to be clicked, then it jumps just past the end of the sequence
and resumes executing the script. On the next pass, the sequence will pick
up where it left off. If whatever condition it stopped for, say a
button it was waiting for had been pressed, it will continue on with
the sequence from that point until it reaches another point where it
can go no further. If the condition it stopped for initially has not been
met on the second pass, it will just skip out of the sequence and try
again on the next loop.
The sequence can contain most of the same basic statements as the
main script can with a few exceptions. SELECT blocks are not allowed
within sequences.
In addition to the standard functions, there are three special functions
that can be used only in a SEQUENCE. These are the WAIT, WHILE, and
the DELAY statements.
WAIT and WHILE
The WAIT statement and the WHILE statement work somewhat alike in that they
cause the sequence to stop until a given set of conditions is TRUE. The
difference is that the WAIT statement requires that the expression in
question go from FALSE to TRUE to be recognized, whereas the WHILE
statement only checks that the statement is TRUE at the time it executes.
To illustrate this a little better, consider the following two
sequences:
// Sequence 1
//
SEQUENCE
WHILE( JS1.B1 );
B1 = TRUE;
DELAY( 10 );
B1 = FALSE;
DELAY( 10 );
ENDSEQUENCE
// Sequence 2
//
SEQUENCE
WAIT( JS1.B1 );
B1 = TRUE;
DELAY( 10 );
B1 = FALSE;
DELAY( 10 );
ENDSEQUENCE
In Sequence 1, the WHILE statement causes the sequence to execute
continuously while JS1.B1 is pressed. The B1 bit will turn on and off
so long as JS1.B1 is pressed.
In Sequence 2, the WAIT statement will allow the sequence to execute
one time when JS1.B1 is first closed. Before the sequence will execute
again, JS1.B1 must be released and then pressed again. For each press of
JS1.B1, B1 will be TRUE, then FALSE, just one time.
DELAY
The DELAY statement causes the sequence to pause for a predetermined time.
The value indicates the number of character-times that the routine is to
delay for. Character time is roughly equivalent to the "Character Rate" set
in the Program Settings tab in the Control Manager GUI. The default value
of 50 means that one increment in the delay value increases the delay time
by about 50 milliseconds.
A sample sequence using DELAY might look like this:
// Wait until Button 4 on JS1 is pressed, then flash Button 1 on the
// CMS Controls 2 times.
//
SEQUENCE
WAIT( JS1.B4 ); // Wait for the JS1 button to get pressed
CMS.B1 = TRUE; // Turn on the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B1 = FALSE; // Turn off the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B1 = TRUE; // Turn on the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B1 = FALSE; // Turn off the CMS Button
ENDSEQUENCE
Every time you pressed JS1.B4, CMS.B1 would turn ON and
OFF twice, each time for about half a second depending on your character
rate.
Nesting
SEQUENCE/ENDSEQUENCE blocks can be nested and can be included in
IF/THEN and IF/THEN/ELSE blocks. Keep in mind that a sequence that's in
one of these does not execute at all if the block is skipped as a result
of the IF, even if the sequence has already been started. It will simply
sit suspended at wherever it was when the IF clause stopped executing.
This can be useful or problematic, depending on what you're trying to
accomplish.