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
Input names in Ruby code?
3 posts
• Page 1 of 1
Input names in Ruby code?
User Guide wrote:It's useful to be able to name connectors, not only for readability (so it's clear what the data represents)
but also because in the case of input connectors the label can be used within your Ruby code as a
variable or as a reference to an input.
That made perfect sense when I red it the first time... but now I'm trying to learn from existing code in stock modules and I've come across something perplexing.
Inside the toggle switch module is some code that stores/changes the Boolean state of the switch and displays part of a gif strip.
One of the connectors is labeled 'setState' and it is clearly the Boolean input where the switch gets set by the preset.
So looking in the code I expect to see it as '@setState' but instead a variable '@on' seems to be there in the role.
So I wonder what happens when you change input names and I found I could change all the input names and the code will still work. So I'm wondering what the actual mechanism for defining input names is.
Can anyone clear up my confusion on this?
- strangeChild
- Posts: 47
- Joined: Sat Apr 27, 2013 8:04 pm
Re: Input names in Ruby code?
it is only used in the event methode and compares the input with the @on variable
it means if i==2 (input ==2)
then compare if @on is not v (value)
so if is not the value at i2
@on takes the value from i2(input 2)
you could also write
like this it is more clear...
i think the switch is a bit "old" and was done before this feature of using the input names like this (i think its since the last version or the one before)
but yes its a bit confusing you also could write
like this there is no extracomparing with the @on variable and it always sets @on to the @setState value when a trigger comes in..
i dont really know which difference this makes because the redraw is done anyway?
- Code: Select all
def event i,v
if i==2
if @on != v
@on = v
output 0,@on
end
end
redraw 0
end
it means if i==2 (input ==2)
then compare if @on is not v (value)
so if is not the value at i2
@on takes the value from i2(input 2)
you could also write
- Code: Select all
def event i,v
if i=='setState'
if @on != v
@on = v
output 0,@on
end
end
redraw 0
end
like this it is more clear...
i think the switch is a bit "old" and was done before this feature of using the input names like this (i think its since the last version or the one before)
but yes its a bit confusing you also could write
- Code: Select all
def event i,v
if i == 'setState'
@on = @setState
output @on
end
redraw
end
like this there is no extracomparing with the @on variable and it always sets @on to the @setState value when a trigger comes in..
i dont really know which difference this makes because the redraw is done anyway?
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: Input names in Ruby code?
Thanks... while I still don't understand everything about what's going on at least I know where to look.
- strangeChild
- Posts: 47
- Joined: Sat Apr 27, 2013 8:04 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 60 guests