LlGetListLength
De DigiWiki.
(Différences entre les versions)
Djphil (discuter | contributions)
(Page créée avec « <lsl> //Basic usage default { state_entry() { list l = ["one", "two", "three"]; integer i = llGetListLength(l); llOwnerSay("there are " + (str… »)
Modification suivante →
(Page créée avec « <lsl> //Basic usage default { state_entry() { list l = ["one", "two", "three"]; integer i = llGetListLength(l); llOwnerSay("there are " + (str… »)
Modification suivante →
Version du 11 août 2012 à 14:57
//Basic usage default { state_entry() { list l = ["one", "two", "three"]; integer i = llGetListLength(l); llOwnerSay("there are " + (string)i + " entries in the list"); } }
Best Practices
When using list length to help you loop through a list, it is better to determine the length first, then start your loop:
integer i = 0; integer length = llGetListLength(mylist); for (; i < length; ++i) { llSay(0, llList2String(mylist, i)); }
The following example is to illustrate what not to do, it calculates the length in the "for" loop and is inefficient because the length gets recalculated at each pass through the loop. This should only ever be done if the list is in fact changing (in length) with each iteration of the loopModèle:Footnote.
integer i; for (i = 0; i < llGetListLength(mylist); ++i) { llSay(0, llList2String(mylist, i)); }