Page 1 of 1
Trigger Switch in Ruby?
Posted: Sat Jun 04, 2016 11:46 am
by adamszabo
Hey guys, I am just wondering is there a way to replicate the behavior of the green "Trigger Switch" in ruby? So basically I have two inputs, a float and a boolean true/false, and the events only get triggered/sent, when the boolean is true. I am thinking something like this but ofcourse it is wrong:
Code: Select all
def event i,v
if == 'knob' & @bool = 1
output 0, @knob
end
end
Thanks!
Re: Trigger Switch in Ruby?
Posted: Sat Jun 04, 2016 12:04 pm
by Tronic
Code: Select all
def event i,v
if i == "knob"
output 0, v if @switch
end
end
Re: Trigger Switch in Ruby?
Posted: Sat Jun 04, 2016 12:07 pm
by adamszabo
ah, thank you very much!

Re: Trigger Switch in Ruby?
Posted: Sat Jun 04, 2016 12:16 pm
by Tronic
this version output the knob value when the switch become true or the knob is moved when the switch is true
Code: Select all
def event i,v
if i == "knob" || "switch"
output 0, @knob if @switch
end
end
Re: Trigger Switch in Ruby?
Posted: Sat Jun 04, 2016 12:34 pm
by adamszabo
I forgot to ask, does this actually prevent the calculation when the switch is off, or it simply blocks the values but it still calculates the knob event? So lets say I have something like this:
Code: Select all
def event i,v
if i == "knob"
@a = some very big and complicated formula
output 0, @a if @switch
end
end
The point is to save cpu when the switch is off, so the even doesnt calculate the stuff inside the code.
Re: Trigger Switch in Ruby?
Posted: Sat Jun 04, 2016 2:28 pm
by Tronic
add all your code, in the "if" check block
Code: Select all
def event i,v
if i == "knob"
if @switch
# this block of code is executed only if switch is true
@a = some very big and complicated formula
output 0, @a
end
end
end
Re: Trigger Switch in Ruby?
Posted: Sat Jun 04, 2016 2:43 pm
by tulamide
Tronic wrote:add all your code, in the "if" check block
Code: Select all
def event i,v
if i == "knob"
if @switch
# this block of code is executed only if switch is true
@a = some very big and complicated formula
output 0, @a
end
end
end
I would reverse it, since there is no need to even check for 'knob' if switch is false:
Code: Select all
def event i,v
if @switch
if i == "knob"
# this block of code is executed only if switch is true
@a = some very big and complicated formula
output 0, @a
end
end
end
or, if the event method as a whole is just executed on knob and switch:
Code: Select all
def event i,v
if not @switch then return end
if i == "knob"
# this block of code is executed only if switch is true
@a = some very big and complicated formula
output 0, @a
end
end
Re: Trigger Switch in Ruby?
Posted: Sat Jun 04, 2016 3:37 pm
by Tronic
tulamide wrote:I would reverse it, since there is no need to even check for 'knob' if switch is false:
Code: Select all
def event i,v
if @switch
if i == "knob"
# this block of code is executed only if switch is true
@a = some very big and complicated formula
output 0, @a
end
end
end
yeah, but this not update the output value when the switch is true and the knob is not moved,
but it has been moved previously.
But of course, it depends on your use.
Code: Select all
def event i,v
if i == "knob" || "switch"
if @switch
# this block of code is executed when the switch is true
# or the switch is true and knob moved
@a = some very big and complicated formula
output 0, @a
end
end
end
Re: Trigger Switch in Ruby?
Posted: Sun Jun 05, 2016 12:10 am
by tulamide
Tronic wrote:yeah, but this not update the output value when the switch is true and the knob is not moved,
but it has been moved previously.
And that is the same behaviour as of the trigger switch, and it was asked for that behaviour. But sure, if you need a trigger on true, even if the knob doesn't change, then my proposal won't work.