Forums > MaxMSP

sunday blues: recreating fquantile in js, code freezes max and error -43

February 11, 2007 | 10:56 am

hi,

i’m trying to do something akin to tables quantile function on a js array.
first of all, it would be nice if anyone could see if this makes sense, i’m a bit of a js newbie.
when i try to invoke the function from max, i get spinning beachball of death. i know js is slow, but stepping through an array can’t be a problem can it?

another small annoyance is that i can’t type the code in textwrangler and then load it into [js file], i get "error -43, opening file", so i need to cut and paste into the max js editor.

can anyone enlighten me on this? code below.

thanks

isjtar

ps running max 4.6.2 on osx 10.4.8, pb G4 1.5Ghz and 1Gb ram

code:

////isolated from larger piece, hope i didn’t miss something
//globals
inlets = 1;
outlets = 0;
autowatch = 1;

//create array
var connectArray = new Array(100);

//reset algorithm
function connectreset() {
i = 0;
while (i<100) {
connectArray[i] = 56;
i++;
}
}

//fquantile

function fquantile() {
var rnd = Math.random();
var total = 0;
for (var index = 0; index < 100; i++) { //get total, index max = array size
total += connectArray[index];
}
//post(total);//check total
for (var index = 0; index > 100; i++) { //compare index sum to total * rnd
sum += connectArray[index];
if (sum >= rnd * total){
return index; //output data
break;
}
}
}


February 11, 2007 | 11:40 am


February 11, 2007 | 11:43 am


February 11, 2007 | 11:55 am

Quote: Patrick Delges wrote on Sun, 11 February 2007 04:43
—————————————————-
> shouldn’t you use "index++" rather than "i++" in fquantile()’s code?
>
> btw, there is a dedicated Javascript mailing list at cycling
>
> p
>
>
—————————————————-

ah damn, changed "all" the ‘i’ for ‘index’, or so i thought.
so is this the equivalent of the fquantile function in table?

yeah sorry about posting here, i was reading another js post on here and not having had my coffee just clicked "new topic".

the js list is not that active though, maybe it would make sense to merge them.

what is the error 43 thing, permissions?
works when i make a new file.

thanks!

isjtar


February 11, 2007 | 12:46 pm


February 11, 2007 | 2:59 pm

Quote: Patrick Delges wrote on Sun, 11 February 2007 05:46
—————————————————-
> That’s where TextWrangler is normally good for. :-)
>
—————————————————-

yeah yeah, rub it in, it’s embarassing enough already ; (


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