Conditional Statements
There are a several constructs that allow you to control the flow of the
script based on the current values of axis and button variables, allowing
one block of code to execute if a particular set of conditions is met,
another block to execute if not.
IF/THEN
The most basic of these is the IF/THEN block. This provides control of the
type:
IF some condition is true THEN do something.
The IF/THEN statements do not require a terminating semicolon.
For example, to do something only if js1.b4 is on, you might write a script
fragment that look like this:
IF( JS1.B4 ) THEN
// Do something
ENDIF
If JS1.B4 is TRUE (pressed) then the statement(s) between the THEN and
the ENDIF are executed. If JS1.B4 is FALSE (released), then that script
segment will be skipped.
The value in the IF statement can also be a more complex expression. For
example, to execute a block of statements if both Button 1 and Button 2 on
JS1 are pressed simultaneously, the scripting might look like this:
IF( JS1.B1 AND JS1.B2 ) THEN
// Do something
ENDIF
ul IF/THEN/ELSE
There is also an IF/THEN/ELSE construct which allows one of two groups of
statements to be executed depending on the state of the expression. It
functions in much the same way as the IF/THEN described above but provides
for a script segment it be executed when the IF statement comes up with a
FALSE result. Like the IF/THEN statements, the IF/THEN statements do not
require a terminating semicolon.
For example, to execute a script segment when JS1.B4 is
pressed and a different script segment when it's not, you might write
this:
IF( JS1.B4 ) THEN
// Do something here if JS1.B4 is TRUE
ELSE
// Do something here if JS1.B4 is FALSE
ENDIF
ul Nesting IF/THEN and IF/THEN/ELSE
IF/THEN and IF/THEN/ELSE sections can be "nested", i.e. an IF or ELSE
clause can contain another IF clause:
IF( JS1.B4 ) THEN
IF( JS1.B5 ) THEN
// Do thing #1
ELSE
// Do thing #2
ENDIF
ELSE
IF( JS1.B6 ) THEN
// Do thing #3
ELSE
// Do thing #4
ENDIF
ENDIF