Trigger Switch in Ruby?

For general discussion related FlowStone
Post Reply
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Trigger Switch in Ruby?

Post 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!
Last edited by adamszabo on Sat Jun 04, 2016 2:46 pm, edited 1 time in total.
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Trigger Switch in Ruby?

Post by Tronic »

Code: Select all

def event i,v
      if i == "knob"
          output 0, v if @switch
      end
end
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Re: Trigger Switch in Ruby?

Post by adamszabo »

ah, thank you very much! :geek:
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Trigger Switch in Ruby?

Post 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
adamszabo
Posts: 667
Joined: Sun Jul 11, 2010 7:21 am

Re: Trigger Switch in Ruby?

Post 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.
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Trigger Switch in Ruby?

Post 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
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Trigger Switch in Ruby?

Post 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
"There lies the dog buried" (German saying translated literally)
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Trigger Switch in Ruby?

Post 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
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Trigger Switch in Ruby?

Post 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.
"There lies the dog buried" (German saying translated literally)
Post Reply