Invalid $KSP_TIMER?

Stevejet
Stevejet Member Posts: 3 Newcomer
edited November 18 in Scripting Workshop

When I use this code (in a multiscript):

on midi_in
if ($MIDI_COMMAND=$MIDI_COMMAND_NOTE_ON)
reset_ksp_timer
$count := 1
while ($count<12)
wait(10000)
add_text_line($back,$count*10 & " " & ($KSP_TIMER/1000))
inc($count)
end while
end if
end on

I get:

10 0
20 39
30 39
40 39
50 39
60 79
70 79
80 79
90 79
100 119
110 119

Please explain the inconsistency between the wait function and $KSP_TIMER.

Comments

  • theodorech
    theodorech Member Posts: 72 Member

    It’d be great if you could clarify what you’re aiming for. Based on your code, the output makes sense; it updates the $back label every time the counter increments (up to 12). The label shows the counter value (1 to 11) multiplied by 10, plus the KSP timer divided by 1000. When the counter hits 12, the label stops at 110 and 119 (counter x10 | timer value).

    Not sure what your while loop is supposed to achieve, but if you want the label to show 0 or 1 instead, you’d need to reset the KSP timer on a MIDI note on event and display that value without involving the counter or the loop in general. Unless I'm missing something :) Cheers!

  • Stevejet
    Stevejet Member Posts: 3 Newcomer

    Thanks for responding.
    I'm sorry; I made the code far more complicated than was necessary. From the KSP manual:
    wait(<wait-time>): Pauses the callback for the specified time in microseconds.
    $KSP_TIMER: This variable returns the time period in microseconds.
    So, for the code:
    reset_ksp_timer
    wait(1000)
    add_text_line($back,$KSP_TIMER)
    wait(1000)
    add_text_line($back,$KSP_TIMER)
    wait(1000)
    add_text_line($back,$KSP_TIMER)
    I should see:
    1000
    2000
    3000
    but what I get is inconsistent values (on each pass) like:
    11
    21
    24
    It makes no difference whether it's in a script or a multiscript.

Back To Top