Cabbage Logo
Back to Cabbage Site

Two or more conditons on gui elements

Hi everyone,

I try to understand how I can have two or more conditions in GUI elements to trigger an event, for example triggering the diskin2 opcode.

For example:

If Knob 1 is in Position “1” and Knob 2 is in Position “5” then a special sample should play.

But with the following code it gets triggered also if only one condition is met.
What is wrong with it, is there a smarter way to do it?

Snippet:

rslider bounds(466, -2, 90, 90), , channel(“switcher”), range(1, 2, 0, 1, 1)
rslider bounds(46, 0, 90, 90), , channel(“switcher2”) , range(3, 4, 0, 1, 1)

instr 1

if changed(chnget:k(“switcher”))==1 then
event “i”, 13, 0, -1, chnget:k(“switcher”)
elseif changed(chnget:k(“switcher”))==2 then
event “i”, 13, 0, -1, chnget:k(“switcher”)

elseif changed(chnget:k(“switcher2”))==1 then
event “i”, 13, 0, -1, chnget:k(“switcher2”)
elseif changed(chnget:k(“switcher2”))==2 then
event “i”, 13, 0, -1, chnget:k(“switcher2”)

endif
endin

instr 13

if(p4 == 1 && p4 == 3) then
a1 diskin2 "D://Cabbage/1.wav
a2 diskin2 "D://Cabbage/1.wav

thanks
//rootnote

The pseudo code would look like this:

   kTrig changed kKnob1, kKnob2
   if kTrig == 1 then
      if kKnob1 == 1 && kKnob2 == 5 then
      //play sample
      endif
   endif

Btw, code is easier to read if you format it. Just select it and then hit the </> button at the top of the editor :+1:

thanks @rorywalsh