How to deselect all other buttons when pressing one button?

Hello,
I have ten buttons that each allows specific groups and disallow others. This works ok, but I'm having an issue with all the other buttons not being deselected when selecting one of them.
I researched the old forum and found this: https://www.native-instruments.com/forum/threads/button-menu-selects-groups.354375/#post-1773979
Unfortunately, it's not working properly for me. Here's the code I have (all the buttons and their IDs have been previously declared):
on init declare const $NUM_BUTTONS := 10 declare $i declare $old_btn declare $sel_btn declare %ID[$NUM_BUTTONS] while ($i < $NUM_BUTTONS) %ID[$i] := get_ui_id($LongSulTasto) + $i inc($i) end while make_persistent($sel_btn) end on function ButtonCB() set_control_par(%ID[$old_btn], $CONTROL_PAR_VALUE, 0) set_control_par(%ID[$sel_btn], $CONTROL_PAR_VALUE, 1) $old_btn := $sel_btn end function on ui_control ($LongSulTasto) $sel_btn := 0 call ButtonCB() end on on ui_control ($LongTremolo) $sel_btn := 1 call ButtonCB() end on on ui_control ($Staccato) $sel_btn := 2 call ButtonCB() end on on ui_control ($GlissDown) $sel_btn := 3 call ButtonCB() end on on ui_control ($GlissHarm) $sel_btn := 4 call ButtonCB() end on on ui_control ($TremHarm) $sel_btn := 5 call ButtonCB() end on on ui_control ($CircularBow) $sel_btn := 6 call ButtonCB() end on on ui_control ($Crunches) $sel_btn := 7 call ButtonCB() end on on ui_control ($ColLegno) $sel_btn := 8 call ButtonCB() end on on ui_control ($BodyTaps) $sel_btn := 9 call ButtonCB() end on on persistence_changed call ButtonCB() end on
Any help would be greatly appreciated. Thanks!
Best Answer
-
Yeah, that is about IDs. You need to declare all ui_buttons in a single block, because declaring a normal variable in between declarations of two UI widgets will steal variable IDs from them, so you won't have a contiguous list of IDs for those buttons then.
So basically remove that
$LongSulTasto_id
variable declaration, you don't need it.0
Answers
-
Please use the Code Block paragraph type when posting code. :)
It works just fine over here...
0 -
Thanks E.D.! I just saw the formatting option, sorry about that.
I'll have to check the rest of the stuff over here. For some reason the buttons are acting up very weirdly.
Thanks again!
0 -
Yeah, this is super weird. I checked the PNG files and the TXT files and all seems to be ok.
The current behaviour is:
I click the first button, everything is ok. I click it again and it remains on.
I click the second one, all ok except if I click it again it deselects itself.
I click the third one, and that one and the second one are selected. If I click it again it deselects itself.
I click the fourth one and that one and the third one are selected, and if I click it again it deselects itself.
Then I click the fifth one and that one, the fourth and the third are selected, and if I click it again it deselects itself.
It gets weirder after that. It's kind of driving me nuts.
0 -
Yeah, no idea. If I just take your code verbatim and add the necessary buttons, it works just fine over here...
0 -
I managed to isolate the issue but I can't figure it out. I added the code for the first custom button image to your code and the button declarations, and was able to reproduce the issue, which has something to do with the IDs.
on init make_perfview set_ui_height_px(350) set_ui_width_px(633) declare ui_button $LongSulTasto declare $LongSulTasto_id $LongSulTasto_id:= get_ui_id ($LongSulTasto) set_text ($LongSulTasto,"") set_control_par_str($LongSulTasto, $CONTROL_PAR_PICTURE, "Button_LongSulTasto") declare ui_button $LongTremolo declare ui_button $Staccato declare ui_button $GlissDown declare ui_button $GlissHarm declare ui_button $TremHarm declare ui_button $CircularBow declare ui_button $Crunches declare ui_button $ColLegno declare ui_button $BodyTaps declare const $NUM_BUTTONS := 10 declare $i declare $old_btn declare $sel_btn declare %ID[$NUM_BUTTONS] while ($i < $NUM_BUTTONS) %ID[$i] := get_ui_id($LongSulTasto) + $i inc($i) end while make_persistent($sel_btn) end on function ButtonCB() set_control_par(%ID[$old_btn], $CONTROL_PAR_VALUE, 0) set_control_par(%ID[$sel_btn], $CONTROL_PAR_VALUE, 1) $old_btn := $sel_btn end function on ui_control ($LongSulTasto) $sel_btn := 0 call ButtonCB() end on on ui_control ($LongTremolo) $sel_btn := 1 call ButtonCB() end on on ui_control ($Staccato) $sel_btn := 2 call ButtonCB() end on on ui_control ($GlissDown) $sel_btn := 3 call ButtonCB() end on on ui_control ($GlissHarm) $sel_btn := 4 call ButtonCB() end on on ui_control ($TremHarm) $sel_btn := 5 call ButtonCB() end on on ui_control ($CircularBow) $sel_btn := 6 call ButtonCB() end on on ui_control ($Crunches) $sel_btn := 7 call ButtonCB() end on on ui_control ($ColLegno) $sel_btn := 8 call ButtonCB() end on on ui_control ($BodyTaps) $sel_btn := 9 call ButtonCB() end on on persistence_changed call ButtonCB() end on
0 -
Yeah, that is about IDs. You need to declare all ui_buttons in a single block, because declaring a normal variable in between declarations of two UI widgets will steal variable IDs from them, so you won't have a contiguous list of IDs for those buttons then.
So basically remove that
$LongSulTasto_id
variable declaration, you don't need it.0 -
Thank you so much Evil Dragon! Declaring all the buttons together solved the issue.
I still had to leave the IDs in or my custom button graphics would be replaced by the generic button graphics on Kontakt.
Thanks again!
0
Categories
- All Categories
- 19 Welcome
- 1.5K Hangout
- 62 NI News
- 786 Tech Talks
- 4.1K Native Access
- 16.6K Komplete
- 2K Komplete General
- 4.3K Komplete Kontrol
- 5.7K Kontakt
- 1.6K Reaktor
- 380 Battery 4
- 847 Guitar Rig & FX
- 429 Massive X & Synths
- 1.3K Other Software & Hardware
- 5.8K Maschine
- 7.3K Traktor
- 7.3K Traktor Software & Hardware
- Check out everything you can do
- Create an account
- See member benefits
- Answer questions
- Ask the community
- See product news
- Connect with creators