Difference between revisions of "LlGetInventoryType"

From Second Life Wiki
Jump to navigation Jump to search
Line 7: Line 7:
|p1_type=string
|p1_type=string
|p1_name=name
|p1_name=name
|func_footnote=Returns the type of the inventory name
|p1_desc=The name of an inventory item.
|return_text
|func_footnote=This function returns the inventory type of the requested inventory item.<br />
If the item does not exist, INVENTORY_NONE is returned.
|return_text=that is the type of the inventory item name
|spec
|spec
|caveats
|caveats
|examples
|examples
|helpers
|helpers=
<lsl>
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.
</lsl>
|related
|related
|also
|also
Line 78: Line 108:
== [[LSL_Type_integer|integer]] llGetInventoryType( [[LSL_Type_string|string]] name); ==
== [[LSL_Type_integer|integer]] llGetInventoryType( [[LSL_Type_string|string]] name); ==
<div style="padding: 0.5em">
<div style="padding: 0.5em">
* name - The name of an inventory item.
* name -  
</div>
</div>
</div>
</div>
Line 87: Line 117:
== Specification ==
== Specification ==
<div style="padding: 0.5em">
<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.




Line 116: Line 145:
== Helper Functions ==
== Helper Functions ==
<div style="padding: 0.5em">
<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.
    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.
</lsl>
</div>
</div>
</div>
</div>

Revision as of 21:49, 25 January 2007

   Outdated templated used

Please change the template from 'LSLFunctionAll' to 'LSL_Function' (just replace 'LSLFunctionAll' with 'LSL_Function', do this after fixing any other erorr messages.

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 The name of an inventory item.

This function returns the inventory type of the requested inventory item.
If the item does not exist, INVENTORY_NONE is returned.

{

Examples

Useful Snippets

<lsl> 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. </lsl>

Deep Notes

Signature

function integer llGetInventoryType( string name );
The correct title of this article is llGetInventoryType. The initial letter is shown capitalized due to technical restrictions.


integer llGetInventoryType( string name);

  • name -

Specification


Caveats

  • Case sensitive

Examples

Helper Functions

See Also

Notes