16
S c r i p t i n g
St r u c t u r e 101
ty p e S
Va r i a b l e S
F l o w
co n t r o l
op e r a t o r S
Fu n c t i o n S
e V e n t S
a n d eV e n t
Ha n d l e r S
S t a t e S
M a n a g i n g
Sc r i p t e d
ob j e c t S
a n lSl
St y l e gu i d e
Su M M a r y
TABLE 1.8: SOME CORE FUNCTIONS TO MANIPULATE LISTS
Fu n c t i o n na M e pu r p o S e
integer llGetListLength(list l)
Gets the number of elements in a list.
integer llListFindList(list l,
list test)
Returns the index of the first instance of test in l, or –1 if it
isn't found.
list llList2List(list l,
integer start, integer end)
Returns the portion of a list, with the specified elements
(similartosubstring).
list llDeleteSubList(list l,
integer start, integer end)
Removes a portion of a list, returns the list minus the specified
elements.
list llListInsertList(list dest,
list snippet, integer pos)
Inserts a list into a list. If pos is longer than the length of dest, it
appends the snippet to the dest.
list llListReplaceList(list dest,
list snippet, integer start,
integer end)
Replaces a part of a list with another list. If the snippet is longer than
the end-start, then it serves to insert elements too.
float llListStatistics(integer
operation, list input)
Performs statistical operations, such as min, max, and standard
deviation, on a list composed of integers and floats. The operation
takes one of ten LIST_STAT_* constants, which are described fully
on the SYW website.
You can use + and += as concatenation operators:
list a = [1,2];
a = a + [3]; // a now contains [1, 2, 3]
a += [4]; // a now contains [1, 2, 3, 4]
While you can't make nested lists, you can insert a list into another:
list myL = ["a", "b"];
list myLL = llListInsertList(myL,[1,2,3,4],1);
// myLL contains [a, 1, 2, 3, 4, b]
Perhaps the most interesting set of string functions deals with converting back and forth
between lists and strings, listed in Table 1.9. For example, the function llDumpList2String()
concatenates the items in a list into a string with a delimiter character sequence separating the list
items; llDumpList2String([1,2,3,4,5], "--") prints "1--2--3--4--5". The function
llList2CSV() is a specialized version, using only commas as separators.
TABLE 1.9: FUNCTIONS THAT CONVERT LISTS TO STRINGS
Fu n c t i o n na M e pu r p o S e
string llDumpList2String(list source,
string delimiter)
Turns a list into a string, with the delimiter between items.
list llParseString2List(string s,
list delimiters, list spaces)
Turns a string into a list, splitting at delimiters and spaces,
keeping spaces. Consecutive delimiters are treated as
one delimiter. Listing 1.4 shows an example of how to use this
function.
list llParseStringKeepNulls(string s,
list delimiters, list spaces)
Turns a string into a list; consecutive delimiters are treated
separately.
list llCSV2List(string csvString)
Convertscomma-separatedvalues(CSVs)toalist.Forinstance,
if csvString is a string "1,2,3" then the list will be [1, 2, 3].
string llList2CSV(list l)
Converts a list to a string containing comma-separated
values(CSVs).
The llParseString2List() is particularly useful because it converts a string's elements to a list
of strings. Listing 1.4 shows an example of how you would call it to break a string into separate items and
then print them to the chat window.