Can I deactivate a activated Button when a other one gets activated?

treynterrio
treynterrio Member Posts: 64 Member

Hi there, can I deactivate a activated Button when a other one gets activated?

I need to do this with a 5 different Buttons, when for example Button 2 is activated and I activate Button 5 the second one should be deactivated and so on.

Comments

  • noY_T
    noY_T Member Posts: 37 Member

    Change button names and numbers as needed

    on init
     declare $i
     declare ui_button $button0
     declare ui_button $button1
     declare ui_button $button2
     declare ui_button $button3
     declare ui_button $button4
     declare %buttonIds[5] := (get_ui_id($button0), get_ui_id($button1), get_ui_id($button2), get_ui_id($button3), get_ui_id($button4))
     declare const $buttonIds__SIZE := 5
    end on
    
    on ui_control($button0)
     $i := 0
     while ($i<num_elements(%buttonIds))
       set_control_par(%buttonIds[$i],$CONTROL_PAR_VALUE,0)
       inc($i)
     end while
     $button0 := 1
    end on
    
    on ui_control($button1)
     $i := 0
     while ($i<num_elements(%buttonIds))
       set_control_par(%buttonIds[$i],$CONTROL_PAR_VALUE,0)
       inc($i)
     end while
     $button1 := 1
    end on
    
    on ui_control($button2)
     $i := 0
     while ($i<num_elements(%buttonIds))
       set_control_par(%buttonIds[$i],$CONTROL_PAR_VALUE,0)
       inc($i)
     end while
     $button2 := 1
    end on
    
    on ui_control($button3)
     $i := 0
     while ($i<num_elements(%buttonIds))
       set_control_par(%buttonIds[$i],$CONTROL_PAR_VALUE,0)
       inc($i)
     end while
     $button3 := 1
    end on
    
    on ui_control($button4)
     $i := 0
     while ($i<num_elements(%buttonIds))
       set_control_par(%buttonIds[$i],$CONTROL_PAR_VALUE,0)
       inc($i)
     end while
     $button4 := 1
    end on
    
  • treynterrio
    treynterrio Member Posts: 64 Member

    THANKS!!! that's exactly what I needed!

    But how I can deactivate the buttons now? One of them is now activated the whole time.

  • noY_T
    noY_T Member Posts: 37 Member

    Add an if statement in the callbacks:

    on ui_control($button0)
     if ($button0=1)
       $i := 0
       while ($i<num_elements(%buttonIds))
         set_control_par(%buttonIds[$i],$CONTROL_PAR_VALUE,0)
         inc($i)
       end while
       $button0 := 1
     end if
    end on
    
Back To Top