Forums > Javascript

js-object timing issue

Nov 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
Nov 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!


Apr 06 2015 | 9:12 am

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?

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

Forums > Javascript