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

Mouse interaction, add and remove items in array or hash.

For general discussion related FlowStone

Mouse interaction, add and remove items in array or hash.

Postby Tronic » Thu May 23, 2013 6:02 am

suppose you have more than one circle,
every one responds to mouse over,
on each circle by clicking with the left mouse button adds some value
and with the right mouse button removes the value from the array or hash.
which method is more convenient to use Array or Hash?

any example in Ruby are welcome.
so to understand, a bit of different approaches to the problem.

thanks to every one.
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Mouse interaction, add and remove items in array or hash

Postby Tronic » Fri May 24, 2013 8:55 am

no interest? :|
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Mouse interaction, add and remove items in array or hash

Postby tester » Fri May 24, 2013 9:58 am

Best practice from SM forum shows, that partial schematics help to solve the problem. Give something to expand.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: Mouse interaction, add and remove items in array or hash

Postby trogluddite » Fri May 24, 2013 8:16 pm

Tronic wrote:which method is more convenient to use Array or Hash?

Well, this depends very much what your data represents, and what you want to do with it.
The main differences are...

Array - just like in SM, you can only reference things by an index number, and the numbers must always be in sequence (an "ordered" array). If the things in your "collection" must always be in a certain order, with no "gaps" in the index numbers, or you might need to "count" through them, this is the one to go for.
Worth noting that, unlike in "green", the items inside the array don't all have to be the same kind; you can mix numbers, strings, graphics objects, you name it, as items in the same array.

Hash
- the indexes are just 'tags' or 'names' for referring to the things in the collection - think of something like an address book; you would be unlikely to "count" through it, but you need to find a person's address by using their name to find it - an index number would be very inconvenient, especially if the index numbers changed every time you added a new friend!
But those index "keys" can be anything you like, not just 'name' strings, so there's nothing to stop you from using numbers as the "tag" names if you want - allowing you to create an array that has "gaps" in the index numbers. But if you wanted to "count" through the items, you would have to use your own code - the standard iterators (e.g. .each, 'for' loops etc.) won't keep the numbers in order for you, and you'd need to program it not to screw up if there was an "empty" index.
There's also another (small) advantage to hashes... Ruby's "object oriented" style suits them very well, and so they are slightly more efficient to look up the values than arrays - but not enough that you should use them when an array would make more sense for your application.

So to decide, ask yourself a few simple questions...
- Is a number the best thing for finding something in the collection?
- Do things need to always keep the same 'index', or do the indexes need to "shuffle up" when adding/deleting?
- Do the items need to be counted through in a predictable order?

Once that is decided, Ruby will have no problem at all doing anything you want with your data - the documentation for Arrays and Hashes shows literally dozens of commands for each one to do almost anything imaginable. So it's your data that will decide, "convenience" just isn't a problem because they are both so versatile in Ruby/
And they are so much more powerful than 'green' because they can contain absolutely any kind of object - even chunks of code to execute.
It's also not immediately obvious, but you can also do something that I always wanted inside SM - multi-dimensional (e.g. [x,y]) arrays. To do that, you make an array where each item inside is also an array - and so on, for as many layers as you like.
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: Mouse interaction, add and remove items in array or hash

Postby RJHollins » Fri May 24, 2013 9:42 pm

... just following along to learn ...

Multi-dimensional arrays !!! :o

Maybe a new topic will emerge that outlines the fundamentals to implement.

please :lol:
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: Mouse interaction, add and remove items in array or hash

Postby tester » Fri May 24, 2013 10:05 pm

A good example to start on :-)
viewtopic.php?f=2&t=1456

As you can see, in greens it uses loops, which is very ineffective.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: Mouse interaction, add and remove items in array or hash

Postby RJHollins » Fri May 24, 2013 10:35 pm

Hi Tester ...

Yes, I've been trying to follow along on several projects of your.
I'm only able to to understand a fraction :lol: but its' all learning for me 8-)

In my 1st project, I am using a 'linked array' concept, as certain sections require several values.
It's working ... but it requires additional components to be added and linked.

I would think that a RUBY handling Multi-dimensional arrays could help simplify the logic and the schematic.

Much in the same way using TROG's example on BUSes [back on the SM forum]. Once I saw that, I immediately set out to put that concept into my project. It greatly simplified my schematic design and logic ... and most important ... it works !! :lol:

I look forward to your posts as always, even if its just conceptually. Sometimes schematics can be difficult for me to decipher at times, but it does help with my thoughts of design for my projects.

This RUBY stuff is very interesting 8-)

As always ... Thank-you!
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: Mouse interaction, add and remove items in array or hash

Postby tester » Fri May 24, 2013 11:26 pm

Well - some of the thigs I do - even I don't understand fully. ;-)
I'm afraid rebuilding my recalc engine into something else is beyond my skills.
I even look inside this one, and wonder "how to heck I made it work?" :mrgreen:

Somehow with ruby, right now I look in it, and don't see it, like reading chinese or hebrew. It's just beyond my buffers at the moment (too many strange little things to remember/recognize at once).
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet


Return to General

Who is online

Users browsing this forum: Majestic-12 [Bot] and 41 guests