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

Re: and arrays again

Postby billv » Mon Nov 04, 2013 12:08 am

tester wrote:This one works reasonably fine

Yeh..the way he's written the index in at all stages is what i was stuck with...
Adjusted my code with it and it's great...got the starting point i was after...
Thanks nubeat7 :D
Code: Select all
def   event i,v,t

if i == 0 then
x = 0               
data=[]
5.times do
data[x]=  @a[x].to_s  + "-" +  @b[x].to_s
x +=1
output 1,t
    end
    output 0,data
    watch data
end
         
end
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: and arrays again

Postby Nubeat7 » Mon Nov 04, 2013 8:00 am

billv wrote:
Code: Select all
def   event i,v,t

if i == 0 then
x = 0               
data=[]
5.times do
data[x]=  @a[x].to_s  + "-" +  @b[x].to_s
x +=1
output 1,t
    end
    output 0,data
    watch data
end

         
end

but like this it is fixed to a length of 5! why not using @a.length or @b.length or get the longest/shortest before
also, when "using 0.upto length|x| do" or "for x in 0..length do" the x would be the iteration so you dont need an extra variable and adding +1 to it each iteration
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: and arrays again

Postby billv » Mon Nov 04, 2013 8:46 am

Nubeat7 wrote: fixed to a length

Yeh...that code was just the starting point.
I added the length fix next, moved the code around a bit so it's easier to work.
brought the de-limiters out as well, so you can use a different one at each stage...
It's looking ok, it's working with float,int or string but I've notice commas won't go through....
Tried to get a gsub thing in there so when there is space in the array you can fill it
with something....but struggled there...so probably have to do it before array goes .to_s

Code: Select all
def   event i,v,t

if i == 0 then

   x = 0               
   data=[]
   d1=@d1
   d2=@d2
   d3=@d3
   d4=@d4
   findlength =[]
   aa = @a.length
   bb = @b.length
   cc = @c.length
   findlength =[aa,bb,cc] 
   c = findlength.each_with_index.max
   d = c.max
   d.times do
     a = @a[x].to_s
     b = @b[x].to_s
     c = @c[x].to_s     
     data[x]=  a + d1 +  b + d2 +  c     
     x +=1   
     end
     output 0,data
     watch  d
end
       
end
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: and arrays again

Postby billv » Mon Nov 04, 2013 12:58 pm

Did the last bit...(providing a default string if array slot empty).worked out well.
The whole thing seems to work great. :D
I fixed up a basic module that's ready to use...
Column Arrays.fsm
(6.35 KiB) Downloaded 807 times

@tester
Note that it functions somewhat like a basic 'router'....
as you've noted before processing the data as it goes through the chain is another story.......
It's good that you've already got Trog's monster system up and running...seems ideal... ;)
That's where I'm going now....
billv
 
Posts: 1157
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia

Re: and arrays again

Postby tester » Mon Nov 04, 2013 1:34 pm

Thanks for efforts. :-)

As for Trogs monster, I digest it, but meanwhile I'm focused on wiring the main structures. The weather isn't helping yet :-]
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 RJHollins » Mon Nov 04, 2013 7:26 pm

Looking good Billv !

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

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 38 guests