javascript timing
Hello,
I realize from reading the docs and this forum that javascript is not for timing-critical tasks. However, I want to use for something where even 100 ms. off won't make a difference. In particular, I want to have a series of processes which randomly update their internal timing. However, when I attempt to measure what the result is (using timer), I'm getting stuff that's pretty far off. It's entirely possible that I'm doing something stupid, or not grasping something. Anyway, the javascript (which wants to be in a file named "debug.js") and the patch follow. I was expecting the number boxes to display approximately the same numbers (which they don't most of the time). thanks!, Michael
inlets = 1;
outlets = 1;
var rOffset = 3000;
var rRange = 2000;
var vcTsk = new Task(vcDo,this);
vcTsk.interval = 4000;
function vcDo()
{
outlet(0,vcTsk.interval);
vcTsk.interval = Math.round(Math.random()*rRange) + rOffset;
}
function msg_int(a){
if (a == 1){
vcTsk.repeat();
}
if (a == 0){
vcTsk.cancel();
}
}
On 23 May 2007, at 00:35, Michael Theodore wrote:
> However, when I attempt to measure what the result is (using
> timer), I'm getting stuff that's pretty far off. It's entirely
> possible that I'm doing something stupid, or not grasping
> something. Anyway, the javascript (which wants to be in a file
> named "debug.js") and the patch follow. I was expecting the number
> boxes to display approximately the same numbers (which they don't
> most of the time). thanks!, Michael
hi michael,
are you comparing the right numbers? maybe stick a [bucket] inbetween.
it seems to work fine over here.
volker.
Thanks very much, Volker! You're absolutely right--I was one off, as bucket demonstrates. Much appreciated!
regards,
Michael