Difference between revisions of "LlGetListLength"

From Second Life Wiki
Jump to navigation Jump to search
m (Error correction)
m (formatted example)
Line 9: Line 9:
|constants
|constants
|examples=
|examples=
<Pre>
<lsl>
default
default
{
{
Line 19: Line 19:
     }
     }
}
}
</Pre>
</lsl>
|notes=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.
|notes=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.
<pre>
<lsl>
list in;
list in;
integer len_in = llGetListLength(in);
integer len_in = llGetListLength(in);
Line 30: Line 30:
integer fneg_len_in = ([] != in);
integer fneg_len_in = ([] != in);
//fneg_len_in and neg_len_in will be the same
//fneg_len_in and neg_len_in will be the same
</pre>
</lsl>
|helpers
|helpers
|also_functions=
|also_functions=

Revision as of 20:37, 18 February 2008

Summary

Function: integer llGetListLength( list src );

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

• list src

Examples

<lsl> default {

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

}

</lsl>

Notes

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

Functions

•  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

Source

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

Signature

function integer llGetListLength( list src );