Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Is there a way?

Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
12-21-2009 05:29
Is there anyway to do a list search for the first number > a number?

Like

If Find List Element that's less than 5 and return the index?
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
12-21-2009 07:16
You could certainly iterate through the list, testing each number against ( < 5) until you find one that passes the test.......

CODE

integer WhereIsIt(list mylist, integer x)
{
integer len = llGetListLength(mylist);
integer count;
while (count < len)
{
if (llList2Integer(mylist,count) < x)
{
return count; // Number < x found at position == count
}
++count;
}
return -1; // No number < x in the list
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-21-2009 14:28
or for huge lists...

<5
sort the list
find the first index of 5
feed the elements before it into a multi find (it's on this forum)

>5
sort the list
find the LAST index of 5 (it's on the forum too)
feed the elements after it to multi find.

there's very few cases where this would be a better option than Roliq pointed out though.

another slight alternative
loop through find looking for all the numbers before or after your target, and keep the lowest returned index. but it'd have to be a pretty big list for this to be efficient... the larger the range tested.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -