From Second Life Wiki
Revision as of 19:10, 13 July 2008 by Chaz Longstaff (Talk | contribs)

Jump to: navigation, search


Function: integer llGetListLength( list src );

Returns an integer that is the number of elements in the list src.

• list src


When using list length to help you loop through a list, it is better to determine the length first, then start your loop:

<lsl> integer i; integer length = llGetListLength(mylist); for (i = 0; i < length; ++i) {

   llSay(0, llList2String(mylist, i));

} </lsl>

The example below which calculates length in the "for" loop is inefficient because length gets recalculated at each pass through the loop (so, to be clear, do it the above way instead.)

<lsl> integer i; for (i = 0; i < llGetListLength(mylist); ++i) {

   llSay(0, llList2String(mylist, i));

} </lsl>

All Issues ~ Search JIRA for related Bugs


<lsl> default {

       list l = ["one", "two", "three"];
       integer i = llGetListLength(l);
       llOwnerSay("there are " + (string)i + " entries in the list");




A faster and lighter (in bytecode) way to determine the length of a list is to do a not-equals compare with a null list. This works because the list not-equals compare returns the difference between the lengths. <lsl> list in; integer len_in = llGetListLength(in); integer flen_in = (in != []); //flen_in and len_in will be the same

integer neg_len_in = -llGetListLength(in); integer fneg_len_in = ([] != in); //fneg_len_in and neg_len_in will be the same </lsl>

See Also


•  llListStatistics LIST_STAT_NUM_COUNT – Returns the number of integers and floats in the list
•  llStringLength Returns the number of characters in a string.

Deep Notes

Search JIRA for related Issues


'linden\indra\lscript\lscript_library\lscript_alloc.cpp' @ lsa_cmp_lists
'linden\indra\lscript\lscript_execute\lscript_execute.cpp' @ list_list_operation


function integer llGetListLength( list src );