Control Statements
Boolean Operators
| Greater than. |
| Less than. |
| Greater than or equal. |
| Less than or equal. |
| Equal. |
| Not equal. |
| True if |
| True if |
| True if |
| True if |
| True only if either |
Remarks
continue
|
---|
Continue statement. Skips the rest of the current iteration if the condition is met. |
Remarks
continue
statement can only be used inside awhile
loop.
Examples
on init declare $i declare $skipped $i := 0 while ($i < 5) inc($i) if ($i <= 3) continue end if inc($skipped) end while message($i & ", " & $skipped) end on
Skipping first three iterations of the while loop. The message will print 5, 2.
See Also
if ... else ... end if
|
---|
Conditional if statement. |
Examples
on controller if (in_range($CC_NUM, 0, 127)) message("CC Number: " & $CC_NUM & " - Value: " & %CC[$CC_NUM]) else if ($CC_NUM = $VCC_PITCH_BEND) message("Pitch Bend - Value: " & %CC[$CC_NUM]) end if if ($CC_NUM = $VCC_MONO_AT) message("Channel Pressure - Value: " & %CC[$CC_NUM]) end if end if end on
Display different text depending on various MIDI controller messages.
See Also
select ()
|
---|
Select-case statement. |
Remarks
This statement is similar to the
if
statement, except that it has an arbitrary number of branches. The expression after theselect
keyword is evaluated and matched against individualcase
branches. The firstcase
branch that matches is executed.The
case
branches may consist of either a single constant number, or a number range expressed by the term "x to y
").While there is no
else
ordefault
case branch in KSP, one can be achieved by usingcase 08000000H to 07FFFFFFFH
, which covers the whole range of 32-bit signed integer values, effectively catching all cases that don't have literally specified branches.
Examples
on controller if ($CC_NUM = $VCC_PITCH_BEND) select (%CC[$VCC_PITCH_BEND]) case -8191 to -1 message("Pitch Bend down") case 0 message("Pitch Bend center") case 1 to 8191 message("Pitch Bend up") case 080000000H to 07FFFFFFH message("We're not sure how you got this Pitch Bend value!") end select end if end on
Query the state of the pitch bend wheel.
See Also
while ()
|
---|
While loop. |
Remarks
If a
while
loop does not contain any counter or await()
/wait_ticks()
command, it will be stopped and exited after 10 million iterations.
Examples
on note ignore_event($EVENT_ID) while ($NOTE_HELD = 1) play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, $DURATION_QUARTER / 2) wait($DURATION_QUARTER) end while end on
Repeating held notes at the rate of one quarter note.
See Also
Events and MIDI: $NOTE_HELD