How to click a label, or area of UI, to select group?

lahatte
lahatte Member Posts: 106 Member
edited October 22 in Scripting Workshop

I want to be able to place some things on the UI, and by clicking on one a specific group gets selected to be able to sound. The simplest way to get started I think is to just use labels.

I haven't been able to find and or understand a way to do this, but I know it is done.

Help! :)

Thanks.

Comments

  • lahatte
    lahatte Member Posts: 106 Member

    Anyone?

    Dragon?

    ;)

  • corbo-billy
    corbo-billy Member Posts: 101 Helper

    A switch or button would be more appropriate for this action.

  • lahatte
    lahatte Member Posts: 106 Member
    edited October 2023

    OK. I'll look into that and see if it will work. Thanks.

    Is there a way to make a switch background hidden, so that only the text is displayed? I can't find anything for that.

  • lahatte
    lahatte Member Posts: 106 Member

    Well, I am not finding anything that works as I need it to. The button and switch work, but I need any that are currently 'pressed' to become not pressed when another one is pressed. How can I achieve that? I don't see any control parameters related to the switch state.

  • corbo-billy
    corbo-billy Member Posts: 101 Helper
  • lahatte
    lahatte Member Posts: 106 Member

    Yes, I already know that logic. If then else WHAT?

  • medusa
    medusa Member Posts: 92 Helper

    to switch a switch off when other is pressed


    on ui_control (switch_2)
    if(switch_2 = 1)
    switch_1 := 0
    end if
    end on
    
  • Gablux
    Gablux Member Posts: 88 Helper

    Please read what you posted "...and by clicking on one a specific group gets selected to be able to sound. The simplest way to get started I think is to just use labels."

    It is hard to understand what you want. I will guess:

    You want a number of buttons on the UI and when any of them are pressed, all the others will be turned off (not pressed) and that pressed button will point to the group you want to play.

    If that's what you want:

    on init
      declare ui_button $button1
      declare ui_button $button2
      declare ui_button $button3
      declare ui_button $button4
    
      declare %button_uiids[4]
        %button_uiids[0] := get_ui_id($button1)
        %button_uiids[1] := get_ui_id($button2)
        %button_uiids[2] := get_ui_id($button3)
        %button_uiids[3] := get_ui_id($button4)
    
      declare $i
      declare $group_to_allow
    end on
    
    
    function clear_buttons
       $i := 0
       while($i < num_elements(%button_uiids))
          set_control_par(%button_uiids[$i], $CONTROL_PAR_VALUE, 0)
          inc($i)
       end while
    end function
    
    
    on ui_control ($button1)
     call clear_buttons
     $button1 := 1
    end on
    
    on ui_control ($button2)
     call clear_buttons
     $button2 := 1
    end on
    
    on ui_control ($button3)
     call clear_buttons
     $button3 := 1
    end on
    
    on ui_control ($button4)
     call clear_buttons
     $button4 := 1
    end on
    
    
    on note
      disallow_group($ALL_GROUPS)
      $i := 0 
      while ($i < num_elements(%button_uiids))
        if ( get_control_par(%button_uiids[$i],$CONTROL_PAR_VALUE) = 1)
          $group_to_allow := $i
        end if
        inc($i)
      end while
      allow_group($group_to_allow)
    end on
    

     good ol' vanilla KSP.

  • lahatte
    lahatte Member Posts: 106 Member

    Thanks for that. I'll give it a go soon.

    I actually decided to just make it so that any sound which had the switch on would play, so multiples can play at once. But what you posted will surely be useful.

    Thanks!

This discussion has been closed.
Back To Top