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

Solved PGS Show/Hide

Discussion in 'Scripting Workshop' started by Reylon, Aug 27, 2021.

  1. Reylon

    Reylon NI Product Owner

    Messages:
    124
    Hi Guys,

    Just wanted to get some info on what am I doing wrong here.

    So basically I have a slider in slot 1 and in slot 2 a button. When the button gets pressed the slider in slot 1 should disappear.

    I think I'm close but I'm missing something.

    Code for slot 1
    Code:
    on init
    set_script_title("slot2")
       declare ui_slider $Slider (0, 1000000)
    hide_part($Slider,$HIDE_WHOLE_CONTROL)
       declare ui_button $button
    pgs_create_key(slot2,1)
    end on
    
    
    on ui_control($button)
    if($button = 1)
    set_control_par(get_ui_id($Slider), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
    pgs_set_key_val(slot2,1,1)
    else
    set_control_par(get_ui_id($Slider), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
    pgs_set_key_val(slot2,1,0)
    end if
    end on
    

    Code for slot 2
    Code:
    on init
    set_script_title("slot2")
       declare ui_slider $Slider (0, 1000000)
    hide_part($Slider,$HIDE_WHOLE_CONTROL)
       declare ui_button $button
    
    declare $slot2_enabled
    end on
    
    
    on pgs_changed
         if(pgs_key_exists(slot2))
         $slot2_enabled := pgs_get_key_val(slot2,1)
    end if
    end on
    
    
    on ui_control($button)
    if($button = 1)
    set_control_par(get_ui_id($Slider), $CONTROL_PAR_HIDE, $HIDE_PART_NOTHING)
    pgs_set_key_val(slot2,1,1)
    else
    set_control_par(get_ui_id($Slider), $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
    pgs_set_key_val(slot2,1,0)
    end if
    end on
    
     
  2. medusa

    medusa NI Product Owner

    Messages:
    239
    Here's a version, and the button to hide is persistent, so it's remembered by the instrument or snapshot.

    Slot 1:

    Code:
    on init
    declare ui_slider $slider(0, 1000000)
    pgs_create_key(HIDE, 1)
    end on
    
    on persistence_changed
    set_control_par(get_ui_id($slider), $CONTROL_PAR_HIDE, 16 * pgs_get_key_val(HIDE, 0) )
    end on
    
    on pgs_changed
    set_control_par(get_ui_id($slider), $CONTROL_PAR_HIDE, 16 * pgs_get_key_val(HIDE, 0) )
    end on
    
    

    Slot 2


    Code:
    on init
    declare ui_button $button
    make_persistent($button)
    end on
    
    on ui_control($button)
    pgs_set_key_val(HIDE, 0, $button)
    end on
    
     
    • Like Like x 1
  3. Reylon

    Reylon NI Product Owner

    Messages:
    124
    Medusa, I gotta say you just saved me a loooot of time. Thank you soo much! Was not expecting a ready script! Definitely learning from this :)
    Thanks again!
     
  4. Reylon

    Reylon NI Product Owner

    Messages:
    124
    Hi Medusa,

    While I was playing with your script I found out that if I click on the button to hide the slider it stays hidden but as soon as I reopen Kontakt the slider appears. Any suggestions how to fix that? Tried a bunch of stuff before posting but doesn't seem to help.
     
  5. medusa

    medusa NI Product Owner

    Messages:
    239
    add the
    pgs_set_key_val(HIDE, 0, $button)
    to the on persistence changed callback
     
  6. Reylon

    Reylon NI Product Owner

    Messages:
    124
    Obviously :oops: Thank you mate! Appreciate it!