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

and arrays again

For general discussion related FlowStone

and arrays again

Postby tester » Sat Nov 02, 2013 1:20 pm

Let say that there are two arrays:

1
2
3
4

a
b
c
d

And I'd like to get:

1 - a
2 - b
3 - c
4 - d

So it wold mean two inputs for two arrays, and custom separator " - " for formatting. How to make it in ruby? How to avoid an error, if two arrays are different in size?
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: and arrays again

Postby billv » Sun Nov 03, 2013 12:42 am

This ones been fun tying to work out as well tester. A bit tricky though.
I did a version that works great, accounts for errors, but is string output,
not array like you need...but In the meantime, still might help... :mrgreen:
Tester array_single output version.fsm
(2.55 KiB) Downloaded 887 times


I can see how the array output can be done...fun challenge.... :D
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: and arrays again

Postby RJHollins » Sun Nov 03, 2013 1:04 am

Question?

Is the '-' anything more than formatting ? If not, you show a 2D array that would then be 'the' data ... and for display purposes you could handle alignment, spacing, '-', etc, all from GUI control [even PRIMS].

Just trying to understand the need.
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: and arrays again

Postby Nubeat7 » Sun Nov 03, 2013 1:10 am

@tester:
Code: Select all
@c= []
0.upto @a.length-1 do |i|
   @c[i] = (@a[i].to_s)+"-"+(@b[i].to_s)
end
output @c


but you need to fix the arrays before with trogs fix_array_size methode
Last edited by Nubeat7 on Sun Nov 03, 2013 1:31 am, edited 1 time in total.
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: and arrays again

Postby billv » Sun Nov 03, 2013 1:12 am

look at testers post again...his needs are very clear...

at the moment , tying to map em both together via loop....
EDIT:
Just saw your post..
Thanks nubeat..will have a go...
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: and arrays again

Postby strangeChild » Sun Nov 03, 2013 2:07 am

Green is not dead...
If it wasn't for the white-space these few primitives would do the trick nicely.
Attachments
closeNoCigar.fsm
(407 Bytes) Downloaded 872 times
strangeChild
 
Posts: 47
Joined: Sat Apr 27, 2013 8:04 pm

Re: and arrays again

Postby trogluddite » Sun Nov 03, 2013 5:49 am

tester wrote:How to make it in ruby? How to avoid an error, if two arrays are different in size?

Depends which you prefer...
- Default value adding to the "short" array.
- Take away surplus from the "long" array.
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: and arrays again

Postby billv » Sun Nov 03, 2013 8:29 am

This was as far as i got..
Code: Select all
def event i,v

if i == 0 then

x = 0
data = Array.new
for i in 1..@a1.length do
data[x] = i = @a1.map.to_s{|x| x}+("-")+ @a2.map.to_s{|x| x}
x += 1
output 0,data
end

end
end

...and result...
Code: Select all
#<Enumerator:0x3abce3c>-#<Enumerator:0x3abcd60>
#<Enumerator:0x3abccac>-#<Enumerator:0x3abcb80>
#<Enumerator:0x3abcb30>-#<Enumerator:0x3abcae0>
#<Enumerator:0x3abca90>-#<Enumerator:0x3abca18>
#<Enumerator:0x3abc978>-#<Enumerator:0x3abc8d8>

:lol: ..

strangeChild wrote:Green is not dead...

nice circuit...
Thanks for the reminder of how much i miss working in green... :)
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: and arrays again

Postby tester » Sun Nov 03, 2013 11:55 am

In greenery I'm doing it like this (see attachement).

I prefer to recalculate the "pool" each time it changes. I could generate one larger, once - and use "string array split", I'm aware of that, but I would have to remember about that limitation too. I'm using this one, because it's easier to adapt, depending on where it is used, and it has no limitation (less to remember - less to worry about). On the other hand - it's slower, or it adds some slowdowns when it's among others.

Now - if the pool is dynamic in size, large, formatting changes "on-the-fly" per click for some reason (don't ask me "why" - that's the part of my movie, where I'm predicting "possible scenarios"), and it's clicked often, then this one adds it's own slowdown to the whole project.

It is used for combinig display and for saving. Not for loading (in terms of processing), because items have associated indexes used separately.

*

So my original question was regarding general simplification. Combine array1 and array2, and place between them a mark with whitespaces (these are a nghtmare sometimes). Add mark with witespaces always after array1, and always before array2, while array1 and array2 may have different amounts of elements.

*

I know I'm doing it in reversed order, but just wanted to post some example. Now I will read and check what you wrote above. :)
Attachments
greenery.fsm
(552 Bytes) Downloaded 880 times
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: and arrays again

Postby tester » Sun Nov 03, 2013 12:03 pm

Nubeat7 wrote:@tester:
Code: Select all
@c= []
0.upto @a.length-1 do |i|
   @c[i] = (@a[i].to_s)+"-"+(@b[i].to_s)
end
output @c


but you need to fix the arrays before with trogs fix_array_size methode


This one works reasonably fine, thanks. First array defines formatting and output size, second is just added and trimmed if it's larger. Actually this trimming might be useful too. White spaces are simply to add (" - " works).
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

Next

Return to General

Who is online

Users browsing this forum: No registered users and 66 guests