LlList2String
Looking for the current API? Open the llList2String reference →
Return value notes
Caveats
- When using this function to typecast a list element to a string it will truncated float based types to 6 decimal places.
Examples
//This code demonstrates the differences in typecasting in LSL (and demonstrates how to use the llList2* functions).
// Best viewed in Chat History (ctrl-h)
default
{
state_entry()
{
list my_list = ["a", "0xFF", "0xFF.FF", "1.0e3", 1, 2.0, <1,2,3>, <1,2,3,4>, llGetOwner()];
integer i = 0;
integer end = llGetListLength(my_list);
for (; i<end; ++i)
{
llOwnerSay("string=" + llList2String(my_list,i)
+ "\n integer=" + (string)llList2Integer(my_list,i) + " OR " +(string)((integer)llList2String(my_list,i))
+ "\n float=" + (string)llList2Float(my_list,i) + " OR " +(string)((float)llList2String(my_list,i))
+ "\n vector=" + (string)llList2Vector(my_list,i) + " OR " +(string)((vector)llList2String(my_list,i))
+ "\n rot=" + (string)llList2Rot(my_list,i) + " OR " +(string)((rotation)llList2String(my_list,i))
+ "\n key=" + (string)llList2Key(my_list,i) + " OR " +(string)((key)llList2String(my_list,i)) );
}
}
}Notes
- If you wish to extract a string from a list that you know will contain only a single item (for example if you extract a single entry from a list using llList2List()), then instead of using
llList2String(myList, 0)you may wish to considering using the more efficient(string)myListas it will produce the same result for single-entry lists with less memory usage due to eliminating a function-call. - To convert a string of hexadecimal notation to integer, call llList2Integer and it will automatically cast the value as decimal integer. To convert that integer back to a string of hexadecimal notation, use a user function like hex.
See also: functions
Shared wiki helpers
The original page also injects shared parameter notes, caveats or issue information through these helpers. Their conditional MediaWiki logic is not reproduced here; inspect the preserved helper source for additional material.
Original shared helper source (conditional wiki logic is not evaluated)
<span title="{{{2}}}" style="border-bottom:1px dotted; cursor:help;">{{#if:{{{3|}}}|{{{3|}}}|{{{1}}}}}</span>Template:LSL Function/list/element
Original shared helper source (conditional wiki logic is not evaluated)
{{LSL Injection Test}}{{LSL_Function/negative index|true|{{{2|none_}}}}}{{#if:
{{#vardefine:p_{{{1|none}}}_desc|List containing the element of interest.}}
{{#vardefine:p_{{{2|none_}}}_desc|Index of the element of interest.}}
{{#vardefine:header_footnote|{{#if:{{{return|}}}|{{#if:{{#var:header_footnote}}|{{#var:header_footnote}}<br/>}}
If {{LSLP|{{{2|none}}}}} describes a location not in {{LSLP|{{{1|none}}}}} then {{{return|}}} is returned.{{#if:{{{3|}}}|<br/>
{{#if:{{{nc|}}}
|If the type of the element at {{LSLP|{{{2|none}}}}} in {{LSLP|{{{1|none}}}}} is not a [[{{{3|}}}{{#var:lang}}|{{{3|}}}]] then {{{return|}}} is returned. <br/>
Here is a workaround: <code>([[{{{3|}}}{{#var:lang}}|{{{3|}}}]])[[llList2String{{#var:lang}}|llList2String]]({{LSL Param|{{{1|none}}}}}, {{LSL Param|{{{2|none}}}}});</code>
|If the type of the element at {{LSLP|{{{2|none}}}}} in {{LSLP|{{{1|none}}}}} is not a [[{{{3|}}}{{#var:lang}}|{{{3|}}}]] it is [[typecast]] to a [[{{{3|}}}{{#var:lang}}|{{{3|}}}]]. {{#if:{{{nf|}}}||If it cannot be typecast {{{return|}}} is returned.}}}}}}|{{#var:header_footnote}}}}}}
}}<includeonly>{{LSLC|List/Read Element{{#var:lang}}}}</includeonly><noinclude>
{| {{Prettytable}}
|-{{Hl2}}
! #var
! value
|-
{{VarPair|p_{{{1|none}}}_desc}}
|-
{{VarPair|p_{{{1|none_}}}_desc}}
|-
{{VarPair|header_footnote}}
|-
{{VarPair|spec}}
|-
{{VarPair|constants_nb}}
|-
{{VarPairTable|also_articles}}
|}
</noinclude>Original wiki source
Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.