Difference between revisions of "List"

From Second Life Wiki
Jump to navigation Jump to search
(reverted to some of the info in the old wiki entry)
m (Reverted edits by Esteth Eponym (Talk); changed back to last version by Quirico Finney)
Line 2: Line 2:
[[Category: LSL Types]]
[[Category: LSL Types]]
[[Category: LSL List]]
[[Category: LSL List]]
Instead of arrays, LSL uses lists. The list {{LSLG|type}} is exactly what it sounds like: a heterogeneous list of the other data types. Lists are created via {{LSLG|csv|comma-separated values (CSV)}} of the other data types. enclosed by square brackets: "[" and "]". See below for examples of the {{LSLG|syntax}}.
A list is a special kind of data type which can contain zero or more elements of any other data type.  
Lists are signified by square brackets surrounding their elements, which are separated by commas.


Lists not only store the {{LSLG|value}} of the list item, but also its type (see {{LSLG|llGetListEntryType}} and {{LSLG|llCSV2List}}). To directly enter a {{LSLG|float}} {{LSLG|value}} into a list, a decimal point (.) must be used.
List examples:
 
<pre>[0,1,2,3,4], ["Yes","No","Perhaps"], [1,14.154,"Isn't this fun?",<0,0,0>]</pre>
Because they store multiple value types, lists are not accessed with square brackets like arrays are. They are read by accessor {{LSLG|functions}} that specify the type of value attempting to be retrieved (e.g. {{LSLG|llList2Integer}}) and written with accessor functions that insert or replace values (or ranges of values) based on new list {{LSLG|variables}} (e.g. {{LSLG|llListReplaceList}}).
 
Note: while the {{LSLG|LSL}} {{LSLG|compiler}} will only accept {{LSLG|code}} with a maximum of 72 items in a list, lists can actually support as many items as a {{LSLG|script}}'s {{LSLG|memory}} will allow. If a list of more than 72 predefined items is needed, just {{LSLG|concatenate}} (combine) two predefined lists into a new one: longlist = firstpart + secondpart;
 
Lists cannot contain other lists, so using them like a multidimensional array is not possible natively (although several ways around this are available). Also, {{LSLG|stride|strided}} lists can be used.
 
Examples:
<pre>//a list with a string, integer, float, vector and rotation
list l = ["somestring",12,3.0,<3.3,4,0>,<0,0,0,1>];</pre>

Revision as of 23:23, 20 February 2007

A list is a special kind of data type which can contain zero or more elements of any other data type. Lists are signified by square brackets surrounding their elements, which are separated by commas.

List examples:

[0,1,2,3,4], ["Yes","No","Perhaps"], [1,14.154,"Isn't this fun?",<0,0,0>]