If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Trigger Switch in Ruby?
9 posts
• Page 1 of 1
Trigger Switch in Ruby?
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:
Thanks!
- 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.
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: Trigger Switch in Ruby?
- Code: Select all
def event i,v
if i == "knob"
output 0, v if @switch
end
end
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: Trigger Switch in Ruby?
ah, thank you very much!
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: Trigger Switch in Ruby?
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
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: Trigger Switch in Ruby?
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:
The point is to save cpu when the switch is off, so the even doesnt calculate the stuff inside the code.
- 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.
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: Trigger Switch in Ruby?
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
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: Trigger Switch in Ruby?
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)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Trigger Switch in Ruby?
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
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
Re: Trigger Switch in Ruby?
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)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 99 guests