js-object timing issue

johannes's icon

hey list,

i just made a js script, wich does a pretty simple thing:
creating a ramp from 0 to n-1 with a delay(ms) after each
increment. (of course something similar is already done as
max externals, but for now i like to understand and recap things with scripting)

when adjusting a very small ms delay value (as argument of the js object)
i get irregular output of js object. it ramps, but not to the
expected value (n-1). in the appended patch i like to ramp to the value 1999. with 20ms everthing working fine, but the smaller the interval gets the bigger the difference between n-1 and the outputs gets. for example:
each time i ramp with 2 ms it stop at different vals. 1976, 1997 etc.

why is it?
is this because the js stuff is executed at low priority at the max sheduler?

i also looked for an alternative to the "task"-way,
but settimeout does not seem to work within the js object…
any workarround within javascript?

Max Patch
Copy patch and select New From Clipboard in Max.

here is the patch and i append the javascript file:

BTW. iam on a macbook 10.6.8 with max 5.1.9.

thanks for your help,

greetings.
johannes

2994.jtest1.js
js
johannes's icon

thanks vanille,

"rep.immediate = 1;" fixed it. i made a test where i count from 0 to 1.000.000 with 2 ms delay and it absolutly matches!

nice,
j

Chris McDonnell's icon

I don't suppose you have the solution to this that you're willing to share.

I've got a similar problem with the timing issue where I want to subtract one from a number every three milliseconds.

Can you help me out please?