## many floats many inlets problem.

Mar 29, 2008 at 11:43pm

# many floats many inlets problem.

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?

#36605
Mar 30, 2008 at 9:59am

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.

#125726
Mar 30, 2008 at 11:01am

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,

#125727
Mar 30, 2008 at 11:09am

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?

#125728
Mar 30, 2008 at 12:34pm

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

#125729

You must be logged in to reply to this topic.