Difference between revisions of "LlGetInventoryType"

From Second Life Wiki
Jump to navigation Jump to search
m (Very minor text changes; replaced <source> with <syntaxhighlight>; added Haiku created with Poem Generator (it doesn't make sense, but Haikus are not necessarily supposed to make sense))
 
(29 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{LSLFunctionAll
{{LSL_Function
|func_id=301
|func_id=301|func_sleep=0.0|func_energy=10.0
|func_sleep=0.0
|func_energy=10.0
|func=llGetInventoryType
|func=llGetInventoryType
|return_type=integer
|return_type=integer
|p1_type=string
|p1_type=string|p1_name=name|p1_desc=name of an inventory item
|p1_name=name
|func_footnote=If {{LSLP|name}} does not exist, [[INVENTORY_NONE]] is returned (no errors or messages are generated), making this function ideal for testing the existence of a certain item in [[inventory]].
|func_footnote=Returns the type of the inventory name
|return_text=that is the type of the inventory item {{LSLP|name}}
|return_text
|spec
|spec
|caveats
|caveats
|examples
|examples=
|helpers
<syntaxhighlight lang="lsl2">
|related
string get_type_info(integer inputInteger)
|also
{
|notes
    if (inputInteger == INVENTORY_TEXTURE)
|constants={| {{Prettytable}}
        return "INVENTORY_TEXTURE";
|- valign="top"
|| '''Flag'''
    else if (inputInteger == INVENTORY_SOUND)
|| '''Value'''
        return "INVENTORY_SOUND";
|| '''Inventory Type'''
|-
    else if (inputInteger == INVENTORY_LANDMARK)
|| <tt>INVENTORY_NONE</tt><br/><tt>INVENTORY_ALL</tt>
        return "INVENTORY_LANDMARK";
|| -1
|| Item does not exist
    else if (inputInteger == INVENTORY_CLOTHING)
|-
        return "INVENTORY_CLOTHING";
|| <tt>INVENTORY_TEXTURE</tt>
|| 0
    else if (inputInteger == INVENTORY_OBJECT)
|| [[texture]]
        return "INVENTORY_OBJECT";
|-
|| <tt>INVENTORY_SOUND</tt>
    else if (inputInteger == INVENTORY_NOTECARD)
|| 1
        return "INVENTORY_NOTECARD";
|| [[sound]]
|-
    else if (inputInteger == INVENTORY_SCRIPT)
|| <tt>INVENTORY_LANDMARK</tt>
        return "INVENTORY_SCRIPT";
|| 3
|| [[landmark]]
    else if (inputInteger == INVENTORY_BODYPART)
|-
        return "INVENTORY_BODYPART";
|| <tt>INVENTORY_CLOTHING</tt>
|| 5
    else if (inputInteger == INVENTORY_ANIMATION)
|| clothing
        return "INVENTORY_ANIMATION";
|-
|| <tt>INVENTORY_OBJECT</tt>
    else if (inputInteger == INVENTORY_GESTURE)
|| 6
        return "INVENTORY_GESTURE";
|| [[object]]
|-
    else if (inputInteger == INVENTORY_SETTING)
|| <tt>INVENTORY_NOTECARD</tt>
        return "INVENTORY_SETTING";
|| 7
|| [[notecard]]
//  else
|-
        return "<!-- inventory type unknown --!>";
|| <tt>INVENTORY_SCRIPT</tt>
}
|| 10
|| [[script]]
|-
|| <tt>INVENTORY_BODYPART</tt>
|| 13
|| body part
|-
|| <tt>INVENTORY_ANIMATION</tt>
|| 20
|| [[animation]]
|-
|| <tt>INVENTORY_GESTURE</tt>
|| 21
|| [[gesture]]
|}
}}


[[Category:LSL_Functions]][[Category:LSL_Stub]]
default
{
    touch_start(integer num_detected)
    {
        integer totalItems = llGetInventoryNumber(INVENTORY_ALL);


{{lowercase|llGetInventoryType}}
        integer index;
__NOTOC__
        while (index < totalItems)
        {
            string itemName = llGetInventoryName(INVENTORY_ALL, index);
            integer type = llGetInventoryType(itemName);


{| width="100%"
            // PUBLIC_CHANNEL has the integer value 0
|-
            llSay(PUBLIC_CHANNEL,
|<div id="box">
                "'" + itemName + "' (" + get_type_info(type) + ")");
== [[LSL_Type_integer|integer]] llGetInventoryType( [[LSL_Type_string|string]] name); ==
<div style="padding: 0.5em">
* name - The name of an inventory item.
</div>
</div>
|-
|
<div id="box">


== Specification ==
            ++index;
<div style="padding: 0.5em">
        }
This function returns the inventory type of the requested inventory item.<br />
    }
If the item does not exist, INVENTORY_NONE is returned.
}
 
</syntaxhighlight>
 
|helpers=<syntaxhighlight lang="lsl2">string InventoryName(string name, integer type)
</div>
</div>
|-
|
<div id="box">
 
== Caveats ==
<div style="padding: 0.5em">
* Case sensitive
</div>
</div>
 
|-
|
<div id="box">
 
== Examples ==
<div style="padding: 0.5em">
</div>
</div>
|-
|
<div id="box">
== Helper Functions ==
<div style="padding: 0.5em">
<lsl>
string InventoryName(string name, integer type)
{//finds an item in a case insensitive fashion of the given type and returns its true name.
{//finds an item in a case insensitive fashion of the given type and returns its true name.
     integer a = llGetInventoryType(name);  
     integer a = llGetInventoryType(name);  
Line 132: Line 85:
         }
         }
     }
     }
     else if((a == type) ^ (!~type))//return name, aslong as a == type or type == INVENTORY_ALL
     else if((a == type) ^ (!~type))//return name, as long as a == type or type == INVENTORY_ALL
     {//we already know that a != INVENTORY_NONE, but just incase we use xor instead of or.
     {//we already know that a != INVENTORY_NONE, but just in case we use xor instead of or.
         return name;
         return name;
     }
     }
Line 142: Line 95:
{//only included to show how this type of check could be done if the value of 'type' is not constant and could be INVENTORY_ALL.
{//only included to show how this type of check could be done if the value of 'type' is not constant and could be INVENTORY_ALL.
     return (llGetInventoryType(name) == type) ^ (!~type);
     return (llGetInventoryType(name) == type) ^ (!~type);
}//Since INVENTORY_ALL == INVENTORY_NONE, the extra part on the end is required to invert the result.
}//Since INVENTORY_ALL == INVENTORY_NONE, the extra part on the end is required to invert the result.</syntaxhighlight>
</lsl>
|also_functions=
</div>
{{LSL DefineRow||[[llGetInventoryAcquireTime]]|Returns the time the item was added to the prim's inventory}}
</div>
{{LSL DefineRow||[[llGetInventoryName]]|Returns the inventory item's name}}
|-
{{LSL DefineRow||[[llGetInventoryNumber]]|Returns the number of items of a specific type in inventory}}
|
{{LSL DefineRow||[[llGetInventoryCreator]]|Returns the inventory item's creator}}
<div id="box">
{{LSL DefineRow||[[llGetInventoryPermMask]]|Returns the inventory item's permissions}}
== See Also ==
{{LSL DefineRow||[[llGetInventoryKey]]|Returns the inventory item's [[UUID]] (if full perm)}}
<div style="padding: 0.5em">
|also_tests=
</div>
{{LSL DefineRow||[[llGetInventoryType_Test]]}}
</div>
|also_articles
|-
|also_events
|
|notes
<div id="box">
|history
== Notes ==
|haiku={{Haiku|Sleepy afternoon|A large, inventory finds|enjoying the type}}
<div style="padding: 0.5em">
|constants={{LSL_Constants_Inventory}}
</div>
|cat1=Inventory
</div>
|cat2
|}
|cat3
 
|cat4
[[Category:LSL_Functions]]
}}
[[Category:LSL_Inventory]]

Latest revision as of 10:02, 13 April 2022

Summary

Function: integer llGetInventoryType( string name );
0.0 Forced Delay
10.0 Energy

Returns an integer that is the type of the inventory item name

• string name name of an inventory item

If name does not exist, INVENTORY_NONE is returned (no errors or messages are generated), making this function ideal for testing the existence of a certain item in inventory.

Flag Inventory Type
INVENTORY_NONE -1 Item does not exist.
INVENTORY_ALL Any inventory type.
INVENTORY_TEXTURE 0 texture
INVENTORY_SOUND 1 sound
INVENTORY_LANDMARK 3 landmark
INVENTORY_CLOTHING 5 clothing
INVENTORY_OBJECT 6 object
Flag Inventory Type
INVENTORY_NOTECARD 7 notecard
INVENTORY_SCRIPT 10 script
INVENTORY_BODYPART 13 body part
INVENTORY_ANIMATION 20 animation
INVENTORY_GESTURE 21 gesture
INVENTORY_SETTING 56 setting
INVENTORY_MATERIAL 57 material

Examples

string get_type_info(integer inputInteger)
{
    if (inputInteger == INVENTORY_TEXTURE)
        return "INVENTORY_TEXTURE";
 
    else if (inputInteger == INVENTORY_SOUND)
        return "INVENTORY_SOUND";
 
    else if (inputInteger == INVENTORY_LANDMARK)
        return "INVENTORY_LANDMARK";
 
    else if (inputInteger == INVENTORY_CLOTHING)
        return "INVENTORY_CLOTHING";
 
    else if (inputInteger == INVENTORY_OBJECT)
        return "INVENTORY_OBJECT";
 
    else if (inputInteger == INVENTORY_NOTECARD)
        return "INVENTORY_NOTECARD";
 
    else if (inputInteger == INVENTORY_SCRIPT)
        return "INVENTORY_SCRIPT";
 
    else if (inputInteger == INVENTORY_BODYPART)
        return "INVENTORY_BODYPART";
 
    else if (inputInteger == INVENTORY_ANIMATION)
        return "INVENTORY_ANIMATION";
 
    else if (inputInteger == INVENTORY_GESTURE)
        return "INVENTORY_GESTURE";
 
    else if (inputInteger == INVENTORY_SETTING)
        return "INVENTORY_SETTING";
 
//  else
        return "<!-- inventory type unknown --!>";
}

default
{
    touch_start(integer num_detected)
    {
        integer totalItems = llGetInventoryNumber(INVENTORY_ALL);

        integer index;
        while (index < totalItems)
        {
            string itemName = llGetInventoryName(INVENTORY_ALL, index);
            integer type = llGetInventoryType(itemName);

            // PUBLIC_CHANNEL has the integer value 0
            llSay(PUBLIC_CHANNEL,
                "'" + itemName + "' (" + get_type_info(type) + ")");

            ++index;
        }
    }
}

Useful Snippets

string InventoryName(string name, integer type)
{//finds an item in a case insensitive fashion of the given type and returns its true name.
    integer a = llGetInventoryType(name); 
    if(!~a)//a == INVENTORY_NONE
    {//it should be noted that INVENTORY_NONE == INVENTORY_ALL == -1; which is why '!~a' works.
        string lc_name = llToLower(name);
        a = llGetInventoryNumber(type);
        while(a)
        {//(a = ~-a) is equivalent to --a, but runs faster.
            if(llToLower(name = llGetInventoryName(type, a = ~-a)) == lc_name)
            {//we found a match ^_^
                return name;
            }
        }
    }
    else if((a == type) ^ (!~type))//return name, as long as a == type or type == INVENTORY_ALL
    {//we already know that a != INVENTORY_NONE, but just in case we use xor instead of or.
        return name;
    }
    return "";//no match ~_~
}

integer InventoryExists(string name, integer type)
{//only included to show how this type of check could be done if the value of 'type' is not constant and could be INVENTORY_ALL.
    return (llGetInventoryType(name) == type) ^ (!~type);
}//Since INVENTORY_ALL == INVENTORY_NONE, the extra part on the end is required to invert the result.

See Also

Functions

•  llGetInventoryAcquireTime Returns the time the item was added to the prim's inventory
•  llGetInventoryName Returns the inventory item's name
•  llGetInventoryNumber Returns the number of items of a specific type in inventory
•  llGetInventoryCreator Returns the inventory item's creator
•  llGetInventoryPermMask Returns the inventory item's permissions
•  llGetInventoryKey Returns the inventory item's UUID (if full perm)

Deep Notes

Tests

•  llGetInventoryType_Test

Signature

function integer llGetInventoryType( string name );

Haiku

Sleepy afternoon
A large, inventory finds
enjoying the type