LSL Wiki Mirror 7-7-7 : llGetInventoryType

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings ::
integer llGetInventoryType(string name)

Returns the type of the inventory item name. Remember, like the other inventory functions, llGetInventoryType is case-sensitive.

This function can be used to check if an inventory item exists in the containing object's inventory.

If the item name is not present in the object's inventory, INVENTORY_NONE is returned and, unlike the other inventory functions, no error message is generated or displayed. This is deliberate.

Flag Value Inventory Type Hex Value
INVENTORY_NONE
INVENTORY_ALL
-1 Item does not exist -1
INVENTORY_TEXTURE 0 texture 0x00
INVENTORY_SOUND 1 sound 0x01
INVENTORY_LANDMARK 3 landmark 0x03
INVENTORY_CLOTHING 5 clothing 0x05
INVENTORY_OBJECT 6 object 0x06
INVENTORY_NOTECARD 7 notecard 0x07
INVENTORY_SCRIPT 10 script 0x0A
INVENTORY_BODYPART 13 body part 0x0D
INVENTORY_ANIMATION 20 animation 0x14
INVENTORY_GESTURE 21 gesture 0x15

Example:
// Says the type of the inventory item named "New Script"

default {
    state_entry() {
        string item_name = "New Script"; // the name of the item we're going to look for.
        
        // this is a list of all the possible inventory types, as constants.
        list list_types = [INVENTORY_NONE, INVENTORY_TEXTURE, INVENTORY_SOUND, INVENTORY_LANDMARK,
        INVENTORY_CLOTHING, INVENTORY_OBJECT, INVENTORY_NOTECARD, INVENTORY_SCRIPT,
        INVENTORY_BODYPART, INVENTORY_ANIMATION, INVENTORY_GESTURE];
        
        // this list is of the string names corresponding to the one above.
        list list_names = ["None", "Texture", "Sound", "Landmark", "Clothing", "Object", "Notecard",
        "Script", "Body Part", "Animation", "Gesture"];
        
        integer detected_type = llGetInventoryType(item_name); // look up which type this object is.
        integer type_index = llListFindList(list_types,[detected_type]); // where in list_types is this type?
        string type_name = llList2String(list_names, type_index); // get the corresponding entry in the names list.
        llSay(0,"The inventory item " + item_name + " is a " + type_name + "."); // say the output.
    }
}

Q: Is there a way to make this not case-sensitive?
A: No, your best option in that case would be to use a loop and check each inventory name individually as in the following example:

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, aslong as a == type or type == INVENTORY_ALL
    {//we already know that a != INVENTORY_NONE, but just incase 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.


Functions | Inventory
There is one comment on this page. [Display comments/form]