Forums > MaxMSP

basic issue, 3 digit ints

April 3, 2010 | 6:26 am

hi i was wondering if theres a way to get 3 digit integers…so 40 is represented with 040 or otherwise if theres a better way to generate random colour values……. i am at the moment randomly generating three ints to the range of 255 then sprintf’ing them. this is fine if all the values are in over 100 but if one is under it ruins this patch.

if this is the best way to do this? is there a way to add a prefix of 0 depending on its value…sorry i am new and cant get my head around if statements in max i might use JS instead but i would like to practice using max over regular scripting.


April 3, 2010 | 8:45 am

As far as setting colour values go, depending on what objects you are setting, it may be possible to use floats (0.0 – 1.0) rather than ints. Wheter that resolves your patch issue is another questtion.

As far as integer padding – I have a vague recollection that this is a modified version of a patch I downloaded from this site quite some time ago. It has the added "feature" of specifying the number of zeroes to pad your output with and handles negative values (more or less).

– Pasted Max Patch, click to expand. –

April 4, 2010 | 2:56 pm

You can do this all with [sprintf symout %03ld] where the 0 sets the padding to use and the 3 is the number of places.

lh


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