I have stolen a part of a script for radio buttons. I have 3 buttons, and button 1 is functioning correctly.
I want it so that if I reselect the same button twice the button stays on, ie it doesn’t toggle off.
I am using the buttons to choose between physical instruments, in conjunction with a midi pedal. My midi pedal selects the correct instrument for whatever patch I am entering, but if I go out of a patch (into the looper patch for instance) I don’t want the selector to deselect upon re-entry.
In my script, SEL1 is working as it should, ie I can select the instrument and click on the midi pedal (or widget on screen) and it does not deselect.
However, SEL2 and SEL3 will deselect when I reclick them. What am I missing here?
I don’t really understand the scripting language, so very happy for any pointers to learn from ground zero, but for now I have gigs coming and need this to work as intended for all 3 buttons, I’d be very gratefull for any pointers!
Script from here:
SEL1, SEL2, SEL3 : Widget //used button’s names
u_last, l_last : Integer // buffer variables to store the last pressed button
//Declaration of widget arrays for upper and lower preset buttons
buttons : Widget Array = [SEL1, SEL2, SEL3]
Initialization //Called on first run
var i : Integer
//Check & store state of buttons - if all off, assume the first as “ON”
For i = 0; i < Size(buttons); i = i + 1 Do
If GetWidgetValue(buttons[i]) == 1.0 Then
u_last = i
u_last = 0
// Called when any of several widgets changed → This is the block for UPPER buttons
On WidgetValueChanged(w : Widget, index: integer, newValue : double) from SEL1, SEL2, SEL3
var i : integer
if newValue == 1.0 and index <> u_last then
// Deselect other buttons
for i = 0; i < Size(buttons); i = i + 1 do
if i <> index then SetWidgetValue(buttons[i],0.0) end
u_last = index
//Prevent a button to be switched off manually If newValue == 0.0 and index == u_last Then SetWidgetValue(buttons[index],1.0) End