Help with avoidng deselect upon reclick of radiobutton

Hi,

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:

var
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
Else
u_last = 0
End
End

End

// 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
end
u_last = index
end

//Prevent a button to be switched off manually
If newValue == 0.0 and index == u_last Then
    SetWidgetValue(buttons[index],1.0)
End

End

The script works for me (I can’t deselect any of the buttons).
Does it work for you in this new gig file?

Radio Button Deselect Test.gig (53.2 KB)

I am able to deselect a widget - by clicking without thinking.
I try do reproduce…

Really? I couldn’t deselect.

Here is another version that uses a different technique to prevent deslection.

Radio Button Deselect Test v2.gig (53.1 KB)

Looks good, until now I cannot deactivate a widget.

Thank you for taking time to help me!
I can also deselect in this gigfile, but only now and then when double.clicking. Like once every 6 tries or so.
The strange thing is in my gigfile btn 1 works perfectly, but 2 and 3 always get deselcted when reclicking two times (not double click necessarily, but simply clicking again twice in a row deselects 2 & 3. Never 1.
Bizarre…

Was this on the “v2” file?

Yes, also in V2, I filmed a short video, had to double click a few times though, first time, only the mixer solo got unsoloed, not the widget, second time widget also.

Here is my gigfile, btn 2 and three selects properly, then clicking again does nothing, second click after initial selecting turns off the button. Every time. On 2 & 3 but not 1…

3 basser STEREO.gig (4.8 MB)

Here’s my problematic gigfile.

Frode

I can reproduce.

1 Like