Forums > Javascript

many floats many inlets problem.

March 29, 2008 | 11:43 pm

Im really confusing myself here although the answer is probs simple, any help would be much appreciated.

I have 15 floats all constantly changing, i need to find the largest and more importantly which one of the float objects sent the largest number so i can use it to trigger a specific msg. I need it to be a constantly changing thing.

I tried using an array to store all the numbers and then using sort() etc but the problem is I need to know which of the fifteen float objects sent the largest number.

One idea i had was to have each float entering a different inlet but how could i have one function for all fifteen inlets or compare variables from different inlets.

Any ideas?

Thanks a lot in advance,


March 30, 2008 | 9:59 am

On 30 Mar 2008, at 00:43, Adam Chambers wrote:
>
> Im really confusing myself here although the answer is probs
> simple, any help would be much appreciated.
>
> I have 15 floats all constantly changing, i need to find the
> largest and more importantly which one of the float objects sent
> the largest number so i can use it to trigger a specific msg. I
> need it to be a constantly changing thing.
>
> I tried using an array to store all the numbers and then using sort
> () etc but the problem is I need to know which of the fifteen float
> objects sent the largest number.

you don’t have to sort the whole array. simply search the max value
and output it’s arrayindex.

in case you are still unsure how to preceed, here is a working script.
btw, Ltop from Lobjects does exactly what you want.

outlets = 2;
function list() {
var input = arguments;
var max = Number.NEGATIVE_INFINITY;
var pos = 0;
for(i=0; i if(input[i] > max) {
max = input[i];
pos = i;
}
}
outlet(1, pos);
outlet(0, max);
}

// volker.


March 30, 2008 | 11:01 am

Cheers mate, The script is exactly what I was after. I had not idea about the object, is there meant to be a prefrence between scripts and objects in terms of speed?

Think il probably stick with scripting because I need to know which float sent thae highest number and send specific msgs dependent on this factor.

Thanks again,


March 30, 2008 | 11:09 am

The LTOP object does exactley what i need it even tells me the position of the float the output the largest number. perfect!

just out of interest is the a difference in speed / CPU usage between max objects and JS scripts?

Thanks for your help


March 30, 2008 | 12:34 pm

On 30 Mar 2008, at 13:09, Adam Chambers wrote:
>
>
> just out of interest is the a difference in speed / CPU usage
> between max objects and JS scripts?
>

yes, there is. max objects are written in C/C++ and execute much
faster than anything in JS, though you’ll probably not notice the
speed difference in most cases.

vb


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