Support

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

Ruby & and'ing

For general discussion related FlowStone

Ruby & and'ing

Postby JB_AU » Fri Aug 01, 2014 11:10 am

Okay i tried some ruby , ruby says it's much like "C" , so i thought if i '&' two arrays and find the matching element, which works 'kinda' , i get the correct result, i don't understand the index based output though;

and'array.png
and'array.png (10.46 KiB) Viewed 6242 times


Result "7"

I really need the result as output ? How can index 0 & 4 also be true ?
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
User avatar
JB_AU
 
Posts: 171
Joined: Tue May 21, 2013 11:01 pm

Re: Ruby & and'ing

Postby trogluddite » Fri Aug 01, 2014 11:57 am

Hi there,

You have the right idea with the '&'. As you can see at the bottom in the 'de-bugging' area, It is returning an Array containing the common elements - it will always return another Array, as it has no idea how many matches there might be, so this ensures that the returned type is consistent for any number of matches.

However, you're not sending the result to the output - the data there is probably the result of a previous experiment, as the ins and outs remember their values, even between FS sessions. You need to use the "output" method to send the result out to the connector.

You then have a choice - you could change the output connector to be String Array type, and just directly output the result...
Code: Select all
output 0, (@in1 & @in2)


If you just want the one match, de-reference the first array item and send that...
Code: Select all
output 0, (@in1 & @in2)[0]


You might need to take care with that to make sure that there is only one match - if the result array is empty, de-referencing will return 'nil' rather than a String. You can do this with an 'if' that checks the array size...
Code: Select all
result = (@in1 & @in2)
if result.size == 1
  output 0, result[0]
else
  # Some other action
end

To treat all of the data as Integers rater than Strings, just change the connectors to Integer Arrays and Integer types - there's only one kind of Ruby Array that can hold data of any type.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Ruby & and'ing

Postby JB_AU » Fri Aug 01, 2014 12:24 pm

Just as i worked out the first part & was curious how to... you answered all my questions (probable the ones i would eventually ask) , cheers mate!

and'array.png
and'array.png (18.26 KiB) Viewed 6236 times
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

Albert Einstein
User avatar
JB_AU
 
Posts: 171
Joined: Tue May 21, 2013 11:01 pm


Return to General

Who is online

Users browsing this forum: No registered users and 71 guests