« Return to Thread: A Basic Question: A list player

A Basic Question: A list player

by chikitin :: Rate this Message:

Reply to Author | View in Thread

Hi Folks,

I am totaly new to Lua. I am trying to make a function called "list_playerXL", so that, it plays the sounds defined in the array named "a" one after another. If you call the function with bl=0, it doesn't randomize them, it simply plays the first n sounds, otherwise ( for any other values for b) it selects m random sounds defined in "a" and play them one after another. Here's how I have tried to do it:


first we define an array of sound as follows:



a={}

a[1]=sound...

...



a[m]=sound...


--The folowing function returns an array containing n elements randomly selected from tbl.

Code:

function n_permuter(tbl, n)
  for i = 1,  n do
    local a,b = math.random(#tbl),math.random(#tbl)
    tbl[a], tbl[b] = tbl[b], tbl[a]
  end
end

---- here's the player! but doesn't work properly.

function list_playerXL(a,m,bl)

   
  a[1]:play()
  local ii=1
 
 
if bl==0 then

 pipmak.schedule(.05,

       function()
             
         repeat              
         if not a[ii]:playing() then
             if not a[ii+1]:playing() then  

                            ii=ii+1
                            a[ii]:play()

                          end          
                      end
       
         if a[ii]:playing() then
                         n = .05
                      else

                            n = nil
                   return n

                      end          
             until ii==m-1        
                      end
          )
else

      a= n_permuter(a, m)
      list_playerXL(a, m, 0)
   
end
end


-- but when i execute the code, it only plays the first sound in the array! I tried list_playerXL(a,6,0). but it plays different number of sounds each time! It seams the repeat loop in the code doesn't work properly.
I couldn't Attach the file ( 5MB) it was saying that the file is too large when i tried to upload it.


Any help would be greatly appreciated.

cs

 « Return to Thread: A Basic Question: A list player