1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Kontakt animation loop script

Discussion in 'Scripting Workshop' started by Scottfthompson, Jan 7, 2022.

  1. Scottfthompson

    Scottfthompson New Member

    Messages:
    3
    I've been through the forums, the KSP, everything. There's lots of opinions and often contradicting ones, but no real answers; I'm just looking for a simple script that can loop an animated slider. Here's what the Kontakt manual gets very close with this, Script. However, it still bounces back and forth. If anyone can answer with KSP what is needed to just loop this knob or a slider's animation, please let us know. Thank you.

    on init
    declare ui_knob $Test (0,99,1)
    declare $direction
    declare $tick_counter
    set_listener($NI_SIGNAL_TIMER_BEAT,12)
    end on
    on listener
    if ($NI_SIGNAL_TYPE = $NI_SIGNAL_TIMER_BEAT)
    if ($direction = 0)
    inc($tick_counter)
    else
    dec($tick_counter)
    end if
    $Test := $tick_counter
    if ($tick_counter = 99)
    $direction := 1
    $Test := 0
    end if
    if ($tick_counter = 0)
    $direction := 0
    end if
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    It's better to animate the picture state of a label, then you can't screw up the animation by clicking/dragging on it.

    Also use modulo when setting the picture state (set the picture state to $tick_counter mod 100) instead of those if clauses. And CODE tags, please.


    Moving to Scripting subforum.
     
    Last edited: Jan 8, 2022
  3. Scottfthompson

    Scottfthompson New Member

    Messages:
    3
    Ok, thank you, lots of new script jargon here for us. Any chance someone could just share an example code of these?
     
  4. JForester

    JForester NI Product Owner

    Messages:
    68
    hi Scot,
    Code:
    on init
    set_listener($NI_SIGNAL_TIMER_MS,88888{vari} )
    declare $animate := 0
    declare ui_slider  $sl_animate (0,127)
    set_control_par(get_ui_id($sl_animate), $CONTROL_PAR_ALLOW_AUTOMATION, 0)
    make_perfview
    declare ui_button $switch_anim
    end on
    
    function animation
        if ($animate < 127)
            inc($animate)
        else
            $animate:=0
        end if
            $sl_animate := $animate
    end function
    
    on listener
        if ($switch_anim=1)
            call animation
        end if
    end on
     
  5. Scottfthompson

    Scottfthompson New Member

    Messages:
    3
    This is fantastic, Thank you JForester. This works well. Thank you so much!
     
  6. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Again a label would be better than a slider. Then all you need to do is:

    Code:
    set_control_par(get_ui_id($label), $CONTROL_PAR_PICTURE_STATE, $counter mod $NUM_FRAMES)
     
  7. JForester

    JForester NI Product Owner

    Messages:
    68
    you are completely right ED:thumbsup:
     
  8. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    I imagine that the reason is that it is difficult not to "slip" on the slider ;) when with a label, you do not risk controlling it with the mouse.
     
  9. JForester

    JForester NI Product Owner

    Messages:
    68
    yes that's right, unless you put a transparent layer on the slider...but that makes the code unnecessarily long.
     
  10. JForester

    JForester NI Product Owner

    Messages:
    68
    Code:
    on init
    {--->  with " $CONTROL_PAR_PICTURE_STATE " control parameter}
    declare $concat_it
    declare $concat_offset
    declare $string_it
    declare $list_it
    declare $preproc_i
    set_listener($NI_SIGNAL_TIMER_MS,88888)
    declare $counter
    declare ui_knob $waitime(10000, 150000, 10000)
    make_persistent($waitime)
    read_persistent_var($waitime)
    declare const $NUM_FRAMES := 128
    declare ui_button $switch_anim
    declare $playing
    declare $exe
    declare ui_label $label(1, 1)
    set_control_par_str(get_ui_id($label),$CONTROL_PAR_PICTURE,"128_frames")
    make_perfview
    end on
    function animation
    while ($exe=1)
    $playing := 1
    set_control_par(get_ui_id($label),$CONTROL_PAR_PICTURE_STATE,$counter)
    inc($counter)
    wait($waitime)
    if ($counter>=$NUM_FRAMES)
    $counter := 0
    end if
    end while
    end function
    on listener
    if ($switch_anim=1)
    $exe := 1
    if ($playing=0)
    call animation
    end if
    else
    $exe := 0
    $counter := 0
    $playing := 0
    end if
    end on
    on ui_control($switch_anim)
    $counter := 0
    end on