LlGetListEntryType

From Second Life Wiki

Jump to: navigation, search

Template:Needs Translation/LSL/de Template:Needs Translation/LSL/es Template:Needs Translation/LSL/el Template:Needs Translation/LSL/he Template:Needs Translation/LSL/it Template:Needs Translation/LSL/ko Template:Needs Translation/LSL/nl Template:Needs Translation/LSL/hu Template:Needs Translation/LSL/no Template:Needs Translation/LSL/da Template:Needs Translation/LSL/sv Template:Needs Translation/LSL/tr Template:Needs Translation/LSL/pl Template:Needs Translation/LSL/pt Template:Needs Translation/LSL/ru Template:Needs Translation/LSL/uk Template:Needs Translation/LSL/zh-Hans Template:Needs Translation/LSL/zh-Hant

Contents

Summary

Function: integer llGetListEntryType( list src, integer index );
194 Function ID
0.0 Delay
10.0 Energy

Returns an integer that is the type of the entry index in src.

• list src List containing the element of interest.
• integer index Index of the element of interest.

index supports negative indexes.
If index describes a location not in src then TYPE_INVALID is returned.

Specification

Index Positive Negative
First 0 -length
Last length - 1 -1

Indexes

  • Positive indexes count from the beginning, the first item being indexed as 0, the last as (length - 1).
  • Negative indexes count from the far end, the first item being indexed as -length, the last as -1.

Type Description
TYPE_INTEGER 1 integer
TYPE_FLOAT 2 float
TYPE_STRING 3 string
TYPE_KEY 4 key
TYPE_VECTOR 5 vector
TYPE_ROTATION 6 rotation
TYPE_INVALID 0 none

Caveats

  • If index is out of bounds the script continues to execute without an error message.
  • If a vector is stored in a list as "<7,5,0>" (as a string type, as opposed to <7,5,0> which is a vector type), its type will be returned as TYPE_STRING, not TYPE_VECTOR. The same applies for "1" being returned as a string instead of an integer, etc. There is no easy way to guess what the type should be from a string value. The users intent may not be obvious

Search JIRA for related Bugs

Examples

Useful Snippets

This function has two primary uses: serializing a list to a string, debugging.

//A simple list serializer and deserializer.
//This will round floats to 6 decimal places and not handle strings with embedded "|" characters
 
string serialize(list input){
    integer len = ~llGetListLength(input);
    string build = (string)(~len);
    while(++len){
        build += "|" + llGetListEntryType(input, len) + 
                 "=" + llList2String(input, len);//very unsafe, list item could contain "|" character!!!
    }
    return build;
}
 
list deserialize(string input){
    integer len = ~(integer)input;//the length is everything before the "|", which is where (integer) stops
    list build = [];
    list pair = llParseString2List(input, ["|"], []);
    string value;
    list replace;
    while(++len){
        integer type = (integer)(value = llList2String(pair, len));
        value = llDeleteSubString(value, 0, llSubStringIndex(value, "="))
        if(TYPE_INTEGER == type)
            replace = [(integer)value];
        else if(TYPE_FLOAT == type)
            replace = [(float)value];
        else if(TYPE_STRING == type)
            replace = [value];
        else if(TYPE_KEY == type)
            replace = [(key)value];
        else if(TYPE_VECTOR == type)
            replace = [(vector)value];
        else if(TYPE_ROTATION == type)
            replace = [(rotation)value];
        pair = llListReplaceList(pair, replace, len, len);
    }
    return pair;
}
 

For a more complex and robust list (de)serializer see TightListType.

See Also

Functions

•  llList2Float
•  llList2Integer
•  llList2Key
•  llList2Rot
•  llList2String
•  llList2Vector

Articles

•  Negative Index

Deep Notes

This article wasn't helpful for you? Maybe the related article at the LSL Wiki is able to bring enlightenment.
In other languages