LSL Wiki Mirror 7-7-7 : llGetListLength

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

Returns the number of elements in the list src.

Example:
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.

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


Functions | List
There is one comment on this page. [Display comments/form]