KSP Stuck on a Script, Second Menu PREV NEXT switches not working ..Please Advise

leon59
leon59 Member Posts: 10 Sine
edited December 2022 in Kontakt

Hello,

I'm about a week in on learning how to script and need some help. I've spent the last several hours trying to get this working but still no joy. 2 menus, 2 sets of PREV/NEXT switches. The first set on menu 1 work , the second set on menu 2 do not. Any help would be greatly appreciated. Thank you.

 on init


  make_perfview

  set_ui_width_px (700)

  set_ui_height_px (200)

  declare const $PAD1_FIRST := 0

  declare const $PAD1_LAST := 3

  declare const $PAD2_FIRST := 4

  declare const $PAD2_LAST := 7

  

  declare $i


  declare ui_menu $pad1_layer

  move_control_px($pad1_layer, 50, 100)

  declare ui_switch $PrevPad1

  move_control_px($PrevPad1, 150, 100)

  declare ui_switch $NextPad1

  move_control_px($NextPad1,250, 100)

  

  declare ui_menu $pad2_layer

  move_control_px($pad2_layer, 400, 100)

  declare ui_switch $PrevPad2

  move_control_px($PrevPad2, 500, 100)

  declare ui_switch $NextPad2

  move_control_px($NextPad2, 600, 100)


  $i := $PAD1_FIRST

  while ($i<=$PAD1_LAST)

   add_menu_item($pad1_layer,group_name($i),$i)

   inc($i)

  end while


  $i:= $PAD2_FIRST

  while ($i<=$PAD2_LAST)

   add_menu_item($pad2_layer,group_name($i),$i)

   inc($i)

  end while

  

  end on


  on ui_control ($pad1_layer)

  $i := $PAD1_FIRST

  while ($i<=$PAD1_LAST)

   purge_group($i,0)

   inc($i)

  end while

  purge_group($pad1_layer,1)

  end on


  on ui_control($PrevPad1)

  $pad1_layer := (get_control_par(get_ui_id($pad1_layer),$CONTROL_PAR_NUM_ITEMS)+$pad1_layer-1) mod get_control_par(get_ui_id($pad1_layer),$CONTROL_PAR_NUM_ITEMS)

  $PrevPad1 := 0

  end on


  on ui_control($NextPad1)

  $pad1_layer := ($pad1_layer +1) mod get_control_par(get_ui_id($pad1_layer),$CONTROL_PAR_NUM_ITEMS)

  $NextPad1 := 0

  end on


  on ui_control ($pad2_layer)

  $i := $PAD2_FIRST

  while ($i<=$PAD2_LAST)

   purge_group($i,0)

   inc($i)

  end while

  purge_group($pad2_layer,1)

  end on


  on ui_control($PrevPad2)

  $pad2_layer := (get_control_par(get_ui_id($pad2_layer),$CONTROL_PAR_NUM_ITEMS)+$pad2_layer-1) mod get_control_par(get_ui_id($pad2_layer),$CONTROL_PAR_NUM_ITEMS)

  $PrevPad2 := 0

  end on


  on ui_control($NextPad2)

  $pad2_layer := ($pad2_layer +1) mod get_control_par(get_ui_id($pad2_layer),$CONTROL_PAR_NUM_ITEMS)

  $NextPad2 := 0

  end on

Comments

  • leon59
    leon59 Member Posts: 10 Sine

    Sorry about the formatting :(

  • leon59
    leon59 Member Posts: 10 Sine

    on init


      make_perfview

      set_ui_width_px (700)

      set_ui_height_px (200)

      declare const $PAD1_FIRST := 0

      declare const $PAD1_LAST := 3

      declare const $PAD2_FIRST := 4

      declare const $PAD2_LAST := 7

      

      declare $i


      declare ui_menu $pad1_layer

      move_control_px($pad1_layer, 50, 100)

      declare ui_switch $PrevPad1

      move_control_px($PrevPad1, 150, 100)

      declare ui_switch $NextPad1

      move_control_px($NextPad1,250, 100)

      

      declare ui_menu $pad2_layer

      move_control_px($pad2_layer, 400, 100)

      declare ui_switch $PrevPad2

      move_control_px($PrevPad2, 500, 100)

      declare ui_switch $NextPad2

      move_control_px($NextPad2, 600, 100)


      $i := $PAD1_FIRST

      while ($i<=$PAD1_LAST)

       add_menu_item($pad1_layer,group_name($i),$i)

       inc($i)

      end while


      $i:= $PAD2_FIRST

      while ($i<=$PAD2_LAST)

       add_menu_item($pad2_layer,group_name($i),$i)

       inc($i)

      end while

      

      end on


      on ui_control ($pad1_layer)

      $i := $PAD1_FIRST

      while ($i<=$PAD1_LAST)

       purge_group($i,0)

       inc($i)

      end while

      purge_group($pad1_layer,1)

      end on


      on ui_control($PrevPad1)

      $pad1_layer := (get_control_par(get_ui_id($pad1_layer),$CONTROL_PAR_NUM_ITEMS)+$pad1_layer-1) mod get_control_par(get_ui_id($pad1_layer),$CONTROL_PAR_NUM_ITEMS)

      $PrevPad1 := 0

      end on


      on ui_control($NextPad1)

      $pad1_layer := ($pad1_layer +1) mod get_control_par(get_ui_id($pad1_layer),$CONTROL_PAR_NUM_ITEMS)

      $NextPad1 := 0

      end on


      on ui_control ($pad2_layer)

      $i := $PAD2_FIRST

      while ($i<=$PAD2_LAST)

       purge_group($i,0)

       inc($i)

      end while

      purge_group($pad2_layer,1)

      end on


      on ui_control($PrevPad2)

      $pad2_layer := (get_control_par(get_ui_id($pad2_layer),$CONTROL_PAR_NUM_ITEMS)+$pad2_layer-1) mod get_control_par(get_ui_id($pad2_layer),$CONTROL_PAR_NUM_ITEMS)

      $PrevPad2 := 0

      end on


      on ui_control($NextPad2)

      $pad2_layer := ($pad2_layer +1) mod get_control_par(get_ui_id($pad2_layer),$CONTROL_PAR_NUM_ITEMS)

      $NextPad2 := 0

      end on

  • Gee_Flat
    Gee_Flat Member Posts: 311 Saw

    Until someone more qualified comes around, I can only ask if its possible that you need to declare more than one variable?

    Maybe $i and $x?

    I don't know.

  • leon59
    leon59 Member Posts: 10 Sine

    Hi Gee_Flat!

    Thank you, will look into that approach. many thanks

  • Gee_Flat
    Gee_Flat Member Posts: 311 Saw


    The more I look at it, it seems like a part of the issue. Your two while loops in the onit assign two different values to the same var.

  • leon59
    leon59 Member Posts: 10 Sine

    Gee_Flat , I'm away from my computer at the mo , I did try with $i and $ii running together but couldn't get that to work either. I'm not sure what you mean by $x? Maybe me trying $ii was the same thing? Will have a look at the KSP manual again but it's not for the faint hearted. I've been a Kontakt supporter since day one and just upgraded to 14 Collector's.Really like to explore KSP more and build a cool instrument. Coming from nothing (script wise) a week ago I'm finding it rather challenging but fun also as I nearly have an instrument built. I just need the +- scroll on both menus to work then I'll be as happy as.... Many thanks

  • Gee_Flat
    Gee_Flat Member Posts: 311 Saw

    X is nothing more than an arbitrary value that I suggested. You could name them $leon_A and $leon_B if you wanted.

    You say you created $ii, but did you replace every instance of $i in your second menu code?

  • leon59
    leon59 Member Posts: 10 Sine

    Yes, I did , understood which is why i tried $ii but ran into other errors which i didn't understand, will try again and report back what they were, the code is up here so easy enough for anybody so inclined to load it into a blank Kontakt and quickly see the issue. The menus are linked through the script though as they split the groups between them. I'm guessing it will be something in the last block that is needed. Like i say I'm only a week into scripting but I wasn't getting any errors thrown up as is which is why I reached out here. Ta

  • leon59
    leon59 Member Posts: 10 Sine

    Same issue with $i , $x :-

      on init


      make_perfview

      set_ui_width_px (700)

      set_ui_height_px (200)

      declare const $PAD1_FIRST := 0

      declare const $PAD1_LAST := 3

      declare const $PAD2_FIRST := 4

      declare const $PAD2_LAST := 7

      

      declare $i

      declare $x


      declare ui_menu $pad1_layer

      move_control_px($pad1_layer, 50, 100)

      declare ui_switch $PrevPad1

      move_control_px($PrevPad1, 150, 100)

      declare ui_switch $NextPad1

      move_control_px($NextPad1,250, 100)

      

      declare ui_menu $pad2_layer

      move_control_px($pad2_layer, 400, 100)

      declare ui_switch $PrevPad2

      move_control_px($PrevPad2, 500, 100)

      declare ui_switch $NextPad2

      move_control_px($NextPad2, 600, 100)


      $i := $PAD1_FIRST

      while ($i<=$PAD1_LAST)

       add_menu_item($pad1_layer,group_name($i),$i)

       inc($i)

      end while


      $x := $PAD2_FIRST

      while ($x<=$PAD2_LAST)

       add_menu_item($pad2_layer,group_name($x),$x)

       inc($x)

      end while

      

      end on


      on ui_control ($pad1_layer)

      $i := $PAD1_FIRST

      while ($i<=$PAD1_LAST)

       purge_group($i,0)

       inc($i)

      end while

      purge_group($pad1_layer,1)

      end on


      on ui_control($PrevPad1)

      $pad1_layer := (get_control_par(get_ui_id($pad1_layer),$CONTROL_PAR_NUM_ITEMS)+$pad1_layer-1) mod get_control_par(get_ui_id($pad1_layer),$CONTROL_PAR_NUM_ITEMS)

      $PrevPad1 := 0

      end on


      on ui_control($NextPad1)

      $pad1_layer := ($pad1_layer +1) mod get_control_par(get_ui_id($pad1_layer),$CONTROL_PAR_NUM_ITEMS)

      $NextPad1 := 0

      end on


      on ui_control ($pad2_layer)

      $x := $PAD2_FIRST

      while ($x<=$PAD2_LAST)

       purge_group($x,0)

       inc($x)

      end while

      purge_group($pad2_layer,1)

      end on


      on ui_control($PrevPad2)

      $pad2_layer := (get_control_par(get_ui_id($pad2_layer),$CONTROL_PAR_NUM_ITEMS)+$pad2_layer-1) mod get_control_par(get_ui_id($pad2_layer),$CONTROL_PAR_NUM_ITEMS)

      $PrevPad2 := 0

      end on


      on ui_control($NextPad2)

      $pad2_layer := ($pad2_layer +1) mod get_control_par(get_ui_id($pad2_layer),$CONTROL_PAR_NUM_ITEMS)

      $NextPad2 := 0

      end on

  • Gee_Flat
    Gee_Flat Member Posts: 311 Saw

    I'd rather be hit over the head with a hammer. $x declaring two values in the init was something that jumped out. I don't know about the rest.

    Is that use of modulo correct, or did you copy a script that had it?

  • leon59
    leon59 Member Posts: 10 Sine

    Copied it from a script which works fine with regards to providing 2 menus for the groups whilst loading and purging the samples.. I just added the switches. I guess it's back to KSP 101. Although the switches work on the first menu they interfere with the loading and purging so obviously there is more to this than meets the eye. I guess they need to be added to with a load purge function also. Like anything it's easy when you know how of course. I'll keep on keeping on and post it here when cracked. Cheers

  • Gee_Flat
    Gee_Flat Member Posts: 311 Saw
    edited December 2022

    My assumption was wrong anyway.

    Once your first while loop runs in the init, it has no more use for the var $i, and as the script runs top>down sequentially, $i can take on a new value.

    My bad! I feel awful for throwing you off track. Last time I answer a script question.

  • leon59
    leon59 Member Posts: 10 Sine

    Managed to sus what I need from various posts from the likes of ED and KSP Fam. Here it is incase anybody wants:-

       on init
    
    
       make_perfview
    
    
      set_ui_width_px (1000)
      set_ui_height_px (575)
    
    
      
       declare const $LAYER1_FIRST := 0
       declare const $LAYER1_LAST := 15
       declare const $LAYER2_FIRST := 0
       declare const $LAYER2_LAST := 15
       
       declare ui_switch $PrevMenu1
       declare ui_switch $NextMenu1
       declare ui_switch $PrevMenu2
       declare ui_switch $NextMenu2
    
    
       declare ui_menu $menu1
       move_control_px($menu1, 50, 100)
       move_control_px($PrevMenu1, 150, 100)
       move_control_px($NextMenu1, 250, 100)
       make_persistent($menu1)
       declare ui_menu $menu2
       move_control_px($menu2, 400, 100)
       move_control_px($PrevMenu2, 500, 100)
       move_control_px($NextMenu2, 600, 100)
       make_persistent($menu2)
    
    
       declare $i
    
    
        $i := $LAYER1_FIRST
       while ($i<=$LAYER1_LAST)
         add_menu_item($menu1,group_name($i),$i)
         inc($i)
       end while
    
    
       $i:= $LAYER2_FIRST
       while ($i<=$LAYER2_LAST)
         add_menu_item($menu2,group_name($i),$i)
         inc($i)
    
    
         end while
    
    
       end on
    
    
       on ui_control($menu1) 
       $i := $LAYER1_FIRST
       while ($i<=$LAYER1_LAST)
       purge_group($i,0)
       inc($i)
       end while
       purge_group($menu1,1)
       purge_group($menu2,1)
       end on
    
    
        on ui_control($PrevMenu1)
        $menu1 := (get_control_par(get_ui_id($menu1),$CONTROL_PAR_NUM_ITEMS)+$menu1-1) mod get_control_par(get_ui_id($menu1),$CONTROL_PAR_NUM_ITEMS)
        $PrevMenu1 := 0
        $i := $Layer1_FIRST
        while ($i<=$Layer1_LAST)
        purge_group($i,0)
        inc($i)
        end while
        purge_group($menu1,1)
        purge_group($menu2,1)
        end on
    
    
        on ui_control($NextMenu1)
        $menu1 := ($menu1 +1) mod get_control_par(get_ui_id($menu1),$CONTROL_PAR_NUM_ITEMS)
        $NextMenu1 := 0
        $i := $LAYER1_FIRST
        while ($i<=$LAYER1_LAST)
        purge_group($i,0)
        inc($i)
        end while
        purge_group($menu1,1)
        purge_group($menu2,1)
        end on
    
    
    
    
        on ui_control ($menu2) 
        $i := $LAYER2_FIRST
        while ($i<=$LAYER2_LAST)
        purge_group($i,0)
        inc($i)
        end while
        purge_group($menu1,1)
        purge_group($menu2,1)
        end on
    
    
        on ui_control($PrevMenu2)
        $menu2 := (get_control_par(get_ui_id($menu2),$CONTROL_PAR_NUM_ITEMS)+$menu2 -1) mod get_control_par(get_ui_id($menu2),$CONTROL_PAR_NUM_ITEMS)
        $PrevMenu2 := 0
        $i := $Layer2_FIRST
        while ($i<=$Layer2_LAST)
        purge_group($i,0)
        inc($i)
        end while
        purge_group($menu1,1)
        purge_group($menu2,1)
        end on
    
    
        on ui_control($NextMenu2)
        $menu2 := ($menu2 +1) mod get_control_par(get_ui_id($menu2),$CONTROL_PAR_NUM_ITEMS)
        $NextMenu2 := 0
        $i := $LAYER2_FIRST
        while ($i<=$LAYER2_LAST)
        purge_group($i,0)
        inc($i)
        end while
        purge_group($menu1,1)
        purge_group($menu2,1)
        end on
    
  • Gee_Flat
    Gee_Flat Member Posts: 311 Saw
    edited December 2022

    Looks great.

    I think the KFL2 instruments might be 970 px wide, if your goal is to be consistent with the current model.

Back To Top