and arrays again

For general discussion related FlowStone
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: and arrays again

Post 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
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: and arrays again

Post 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
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: and arrays again

Post 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
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: and arrays again

Post 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....
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: and arrays again

Post 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 :-]
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: and arrays again

Post by RJHollins »

Looking good Billv !

:)
Post Reply