View Full Version : query an array variable?
dunkel3d 07-16-2003, 03:54 PM Is there a way to retrieve the index number of the lowest value in a float array?
Flash action scripting allows you to do this with certain commands if I remember correctly.
S:hmm:
|
|
I don't belive there is a mel command to do this, but it shouldn't be that hard to look through the array and find it.
I can think of two ways to do this...
// First way
float $myArray[]={9.0, 1000, 32, 4, 65};
float $buffer[]=`sort $myArray`;
int $lowest;
for($i=0;$i<size($myArray);$i++)
{
if($myArray[$i] == $buffer[0])
{
$lowest=$i;
break;
}
}
The other way is like this...
float $myArray[]={9.0, 1000, 32, 4, 65};
float $small = 1000;
int $lowest;
for($i=0;$i<size($myArray);$i++)
{
if($myArray[$i] < $small)
{
$small = $myArray[$i];
$lowest=$i;
}
}
I think the first method may be a little fast, but depending on the size of your arrays it might not matter.
george
dunkel3d
07-16-2003, 08:01 PM
GDC you are brilliant.
Thanks
S
CGTalk Moderation
01-15-2006, 04:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.