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?
Trigger Switch in Ruby?
Code: Select all
def event i,v
if == 'knob' & @bool = 1
output 0, @knob
end
end
Thanks!
Re: Trigger Switch in Ruby?
Code: Select all
def event i,v
if i == "knob"
output 0, v if @switch
end
endRe: Trigger Switch in Ruby?
Re: Trigger Switch in Ruby?
Code: Select all
def event i,v
if i == "knob" || "switch"
output 0, @knob if @switch
end
endRe: Trigger Switch in Ruby?
Code: Select all
def event i,v
if i == "knob"
@a = some very big and complicated formula
output 0, @a if @switch
end
endThe 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?
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
endRe: Trigger Switch in Ruby?
Tronic wrote:add all your code, in the "if" check blockCode: 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
endor, 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
endRe: 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
endRe: 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.