Skip to content
lsl.devlsl.devLSL Dev

llGetInventoryType

function
Function syntax
integer llGetInventoryType(
  1. string item// Name of the item in the prim's inventory.
);
Returns
integer
Energy
10

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.

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

How to use
integer result = llGetInventoryType("");
FlagInventory Type
INVENTORY_NONE-1Item does not exist.
INVENTORY_ALLAny inventory type.
INVENTORY_TEXTURE0texture
INVENTORY_SOUND1sound
INVENTORY_LANDMARK3landmark
INVENTORY_CLOTHING5clothing
INVENTORY_OBJECT6object
FlagInventory Type
INVENTORY_NOTECARD7notecard
INVENTORY_SCRIPT10script
INVENTORY_BODYPART13body part
INVENTORY_ANIMATION20animation
INVENTORY_GESTURE21gesture
INVENTORY_SETTING56setting
INVENTORY_MATERIAL57material
Example 1
47 collapsed lines
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
7 collapsed lines
llSay(PUBLIC_CHANNEL,
"'" + itemName + "' (" + get_type_info(type) + ")");
++index;
}
}
}
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.
17 collapsed lines
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.
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.