chikitin wrote:
> --The folowing function returns an array containing n elements
> randomly
> selected from tbl.
No. It performs n random transpositions on 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
The # operator is new in Lua 5.1, and Pipmak still uses 5.0 (will
update to 5.1 in version 0.3, whenever that is). In Lua 5.0, you use
table.getn(tbl). You should have gotten an error message about this.
> ---- 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'm having some trouble understanding that code. Your scheduled
function only ever returns nil or nothing, and therefore is only run
once, is that what you want? What's the point of assigning .05 to n
when that value is never used (the only place where n is used is in
"return n", and there you set it to nil just before)? (Is the return
statement placed where you meant to place it? Your indentation is a
bit odd so it's easy to miss.) Your repeat loop spins a large number
of times while sounds are playing, using 100% CPU and blocking all
other Pipmak activity, is that what you want?
Here's how I would clean it up into something that does approximately
what you want (untested):
function list_playerXL(a,m,bl)
if bl ~= 0 then
n_permuter(a, 30)
end
a[1]:play()
local ii=1
pipmak.schedule(.05,
function()
if ii == m then
return nil
end
if not a[ii]:playing() then
ii=ii+1
a[ii]:play()
end
return .05
end
)
end
> I tried list_playerXL(a,6,0). but it plays different number of
> sounds each
> time!
I'm not sure why it would do that, at a glance, but I don't have time
to test it or analyze it in detail right now. I'll have a closer look
tomorrow if you can't figure it out until then.
> I couldn't Attach the file ( 5MB) it was saying that the file is too
> large
> when i tried to upload it.
Yes, we'd rather not spam all list subscribers with 5MB files. Why is
it so big, anyway? I'd imagine that you should be able to strip down
an example project for this to a few dozen KB. If it must be that big,
then you're better off putting it on some web server or file hosting
service and posting a link than sending it directly through the list.
-Christian
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial.
http://p.sf.net/sfu/www-adobe-com_______________________________________________
Pipmak-Users mailing list
Pipmak-Users@...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users