I'm trying to write a function which simulates dialing:
<<set $nmbrs=["dial0.wav","dial1.wav","dial2.wav","dial3.wav","dial4.wav","dial5.wav","dial6.wav","dial7.wav","dial8.wav","dial9.wav"]>>
<<set $dial=
function(number)
{function delay(i)
{var d=eval(number[i]);if (!d) d=10;return 666+d*160;}
var code='<<timedcontinue 0.5>>';dur=500;
for (var i=0;i<number.length;++i)
{t=$nmbrs[eval(number[i])];
code=code+'<<playsound "'+t+'">><<timedcontinue '+delay(i)/1000+'>>\n';
dur+=delay(i);
}
//alert(code);
new Wikifier(document.createElement('div'), code);
return dur/1000;
}
>>
<<timedcontinue $dial("99876543201")>>\
(My modification of timedcontinue macro accepts the time in seconds only, the rest is the same as in the standard one)
If I uncomment the alert, everything works great, and this is what the alert shows:
<<timedcontinue 0.5>><<playsound "dial9.wav">><<timedcontinue 2.106>>
<<playsound "dial9.wav">><<timedcontinue 2.106>>
<<playsound "dial8.wav">><<timedcontinue 1.946>>
<<playsound "dial7.wav">><<timedcontinue 1.786>>
<<playsound "dial6.wav">><<timedcontinue 1.626>>
<<playsound "dial5.wav">><<timedcontinue 1.466>>
<<playsound "dial4.wav">><<timedcontinue 1.306>>
<<playsound "dial3.wav">><<timedcontinue 1.146>>
<<playsound "dial2.wav">><<timedcontinue 0.986>>
<<playsound "dial0.wav">><<timedcontinue 2.266>>
<<playsound "dial1.wav">><<timedcontinue 0.826>>
These delays are correct for every digit and works OK.
But if I remove the alert, the first delay becomes about 10 times shorter it should be! Not 0, however (I found it out by increasing all delays 10 times - then the 1st one becomes normal, while all the rest becomes huge). So the second digit sound starts playing way before the first one ends. That's true for any first digit - 0,9,1, etc.
What's the reason and how to fix it?
Comments
I'm completely stuck. Pleeease help!