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

Select per button

Discussion in 'Scripting Workshop' started by Reylon, Dec 31, 2021.

  1. Reylon

    Reylon NI Product Owner

    Messages:
    124
    Hi Guys, and happy new year to all :)

    Im curious how to get the B buttons separated from A buttons so when A buttons are clicked it don't interfear with B buttons.
    Code:
    on init
      declare %ids[8]
      declare ui_switch $B1
      declare ui_switch $B2
      declare ui_switch $B3
      declare ui_switch $B4
      declare ui_switch $A1
      declare ui_switch $A2
      declare ui_switch $A3
      declare ui_switch $A4
    
      %ids[0] := get_ui_id($B1)
      %ids[1] := get_ui_id($B2)
      %ids[2] := get_ui_id($B3)
      %ids[3] := get_ui_id($B4)
      %ids[4] := get_ui_id($A1)
      %ids[5] := get_ui_id($A2)
      %ids[6] := get_ui_id($A3)
      %ids[7] := get_ui_id($A4)
      declare $_i
    end on
    
    
    
    on ui_control($B1)
      $_i := 0
      while ($_i<num_elements(%ids))
        if (%ids[$_i] # get_ui_id($B1))
          set_control_par(%ids[$_i],$CONTROL_PAR_VALUE,0)
        end if
        inc($_i)
      end while
    end on
    on ui_control($B2)
      $_i := 0
      while ($_i<num_elements(%ids))
        if (%ids[$_i] # get_ui_id($B2))
          set_control_par(%ids[$_i],$CONTROL_PAR_VALUE,0)
        end if
        inc($_i)
      end while
    end on
    on ui_control($B3)
      $_i := 0
      while ($_i<num_elements(%ids))
        if (%ids[$_i] # get_ui_id($B3))
          set_control_par(%ids[$_i],$CONTROL_PAR_VALUE,0)
        end if
        inc($_i)
      end while
    end on
    on ui_control($B4)
      $_i := 0
      while ($_i<num_elements(%ids))
        if (%ids[$_i] # get_ui_id($B4))
          set_control_par(%ids[$_i],$CONTROL_PAR_VALUE,0)
        end if
        inc($_i)
      end while
    end on
    
    
    on ui_control($A1)
      $_i := 0
      while ($_i<num_elements(%ids))
        if (%ids[$_i] # get_ui_id($A1))
          set_control_par(%ids[$_i],$CONTROL_PAR_VALUE,0)
        end if
        inc($_i)
      end while
    end on
    on ui_control($A2)
      $_i := 0
      while ($_i<num_elements(%ids))
        if (%ids[$_i] # get_ui_id($A2))
          set_control_par(%ids[$_i],$CONTROL_PAR_VALUE,0)
        end if
        inc($_i)
      end while
    end on
    on ui_control($A3)
      $_i := 0
      while ($_i<num_elements(%ids))
        if (%ids[$_i] # get_ui_id($A3))
          set_control_par(%ids[$_i],$CONTROL_PAR_VALUE,0)
        end if
        inc($_i)
      end while
    end on
    on ui_control($A4)
      $_i := 0
      while ($_i<num_elements(%ids))
        if (%ids[$_i] # get_ui_id($A4))
          set_control_par(%ids[$_i],$CONTROL_PAR_VALUE,0)
        end if
        inc($_i)
      end while
    end on
    
    
    
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Have two variables that retain the pressed state value (0-3) for A group and for B group. Do the value adjustment loop in a function that you call after you set the value for that variable - this makes the code way cleaner.

    You do the value setting in one loop that runs for half as long (up to 4, not up to 8), then you set the values of A buttons and B buttons in one go.
     
  3. Reylon

    Reylon NI Product Owner

    Messages:
    124
    Thank you ED,
    will have to check that out. Meanwhile I tried to play with the saturation fx but can't seem to understand how the saturation menu presets, enhanced, classic, drums works also there is no info about that in KSP?
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yes there is. Make sure you check out the very latest KSP reference.
     
  5. Reylon

    Reylon NI Product Owner

    Messages:
    124
    Thanks ED, I actually seem to have the latest version of KSP and under the saturation section I can’t find anything else than the engine part…Could you please point me to the right page? :)
     
  6. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Page 211. It needs to be a bit restructured so that this info is moved to the respective effect's section (just like it was for i.e. Supercharger, Replika, etc.)
     
    • Like Like x 2
  7. Reylon

    Reylon NI Product Owner

    Messages:
    124
    Thank you, I can't seem to remember how to add $NI_SHAPE_TYPE_CLASSIC on the same line as the ENGINE_PAR. Or is this the right way of doing it?
    Code:
    on ui_control ($Compressor_Menu)
            select ($Compressor_Menu)
            case 0
                set_engine_par($ENGINE_PAR_COMP_TYPE,$Compressor_Menu,-1,3,-1)
                set_engine_par($NI_COMP_TYPE_CLASSIC,$Compressor_Menu,-1,3,-1)
            case 1
                set_engine_par($ENGINE_PAR_COMP_TYPE,$Compressor_Menu,-1,3,-1)
                set_engine_par($NI_COMP_TYPE_ENHANCED,$Compressor_Menu,-1,3,-1)
            case 2
                set_engine_par($ENGINE_PAR_COMP_TYPE,$Compressor_Menu,-1,3,-1)
                set_engine_par($NI_COMP_TYPE_PRO,$Compressor_Menu,-1,3,-1)
        end select
    end on
     
    Last edited: Jan 9, 2022
  8. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    It's the value you use (not $Compressor_Menu). That said if you use $NI_COMP_TYPE_xyz as values for your menu entries, that will work too.