Page 2 of 2

Re: and arrays again

Posted: Mon Nov 04, 2013 12:08 am
by billv
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

Re: and arrays again

Posted: Mon Nov 04, 2013 8:00 am
by Nubeat7
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

Re: and arrays again

Posted: Mon Nov 04, 2013 8:46 am
by billv
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

Re: and arrays again

Posted: Mon Nov 04, 2013 12:58 pm
by billv
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 957 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....

Re: and arrays again

Posted: Mon Nov 04, 2013 1:34 pm
by tester
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 :-]

Re: and arrays again

Posted: Mon Nov 04, 2013 7:26 pm
by RJHollins
Looking good Billv !

:)