function loopthrough (i) {
i++;
if (i <= 20) {
play_multi_sound("aud"+i);
$("#debug").html(i);
setTimeout("loopthrough("+i+");",242); }
else {
loops++;
$("#debug").html("rest");
$("#loops").html(loops);
setTimeout("loopthrough("+0+");",1000);
}
}
Does my code look like it is forking? since after about 3 loops it is litrally crashing the browser. I am using excessive HTML5 audio since I like to test new features and whilst im still a newbie at Javascript I really need this code to work. (Im making a simple beat game in canvas where you use a pong style paddle and each ball you hit of varying speed it will play a sound, thus making a cool beat)… Atm im just testing the capabilities of alot of audio being looped through at once.
So yeah my basic question is “Is my code efficient, is it forking and is there anyway of improving this greatly if you know of a better way?”
Thanks,
Tom C.
EDIT:
Just removed my loops++; (for some reason it was returning NaN even though it was defined as global) and it actually successfully looped 20 times without flaws.
I just did some tests, and I am sticking it here so that the code is clear.
That worked fine and it never crashed. And it didn’t fork either.
So, it’s crashing on something else.
I would try this in another browser as well, and see if it crashes – could just be the FF beta 8 crashing.
Try removing 1 bit at a time from it and see if it starts to work – it’s a good way to narrow down the culprit.
I bet it’s the audio that’s crashing it…
* update *
Try bumping up the timeout delay – it could be that the audio doesn’t finish and then attempts to play again and is somehow backlogging.