Difference between revisions of "LlGetListEntryType"

From Second Life Wiki
Jump to navigation Jump to search
m
m (added example)
Line 13: Line 13:
|constants=
|constants=
{{LSL_Constants/ListEntryType}}
{{LSL_Constants/ListEntryType}}
|examples
|examples=
<lsl>
string get_list_entry_type_info(integer inputInteger)
{
    if (inputInteger == 1)
        return "integer";
    else if (inputInteger == 2)
        return "float";
    else if (inputInteger == 3)
        return "string";
    else if (inputInteger == 4)
        return "key";
    else if (inputInteger == 5)
        return "vector";
    else if (inputInteger == 6)
        return "rotation";
 
    else
        return "<!-- invalid type --!>";
}
 
default
{
    touch_start(integer num_detected)
    {
        list listOfStuff = [
            <1.0, 2.0, 3.0, 4.0>,
            <1.0, 2.0, 3.0>,
            TEXTURE_BLANK,
            "some random text",
            382.4,
            1];
 
        integer index = llGetListLength(listOfStuff);
 
        // start with (length - 1) and end with 0
        while (--index)
        {
            integer type = llGetListEntryType(listOfStuff, index);
            string entry2string = llList2String(listOfStuff, index);
 
            // PUBLIC_CHANNEL has the integer value 0
            llSay(PUBLIC_CHANNEL,
                "'" + entry2string + "' has the list-entry-type: '" + get_list_entry_type_info(type) + "'");
        }
    }
}
</lsl>
|helpers=This function has two primary uses: serializing a list to a string, debugging.
|helpers=This function has two primary uses: serializing a list to a string, debugging.
<lsl>//A simple list serializer and deserializer.
<lsl>//A simple list serializer and deserializer.

Revision as of 06:27, 6 October 2012

{{LSL_Function |inject-2= |func_id=194|func_sleep=0.0|func_energy=10.0 |func=llGetListEntryType|return_type=integer |p1_type=list|p1_name=src |p2_type=integer|p2_name=index |func_footnote |func_desc |return_text=that is the type of the entry index in src. |spec |caveats=

  • 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

|constants=

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

|examples= <lsl> string get_list_entry_type_info(integer inputInteger) {

   if (inputInteger == 1)
       return "integer";

   else if (inputInteger == 2)
       return "float";

   else if (inputInteger == 3)
       return "string";

   else if (inputInteger == 4)
       return "key";

   else if (inputInteger == 5)
       return "vector";

   else if (inputInteger == 6)
       return "rotation";
   else
       return "