Forums > Javascript

js-object timing issue

November 29, 2011 | 2:40 pm

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?

here is the patch and i append the javascript file:

– Pasted Max Patch, click to expand. –

BTW. iam on a macbook 10.6.8 with max 5.1.9.

thanks for your help,


  1. jtest1.js
November 29, 2011 | 5:09 pm

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!


Viewing 2 posts - 1 through 2 (of 2 total)

Forums > Javascript