Don't click here unless you want to be banned.

LSL Wiki : llGetListLength

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are
integer llGetListLength(list src)

Returns the number of elements in the list src.

list foo = ["bar", "baz"];
llOwnerSay((string) llGetListLength(foo));

This example will make the object say "2" to the object owner.

llGetListLength returns the number of elements in a list, not the maximum index in a list. To loop through all the elements in a list, use this:

list MyList = ["a","b","c"];
integer length = llGetListLength(MyList);
integer i;
for (i = 0; i < length; ++i) {
    llOwnerSay(llList2String(MyList, i));

Note: In the above example, the length integer is declared, calling llGetListLength a single time, rather than calling it within the for loop. As this forum thread discusses, doing it this way results in a much faster loop.

list MyList = ["a","b","c"];
integer length_slow = llGetListLength(MyList); //Slow
integer length_fast = (MyList != []); //Fast
integer neg_length_fast = ([] != MyList); //Fast & negative

This article wasn't helpful for you? Maybe the related article at the LSL Portal is able to bring enlightenment.

Functions | List
There are 2 comments on this page. [Display comments/form]