Difference between revisions of "LlGetInventoryKey"

From Second Life Wiki
Jump to navigation Jump to search
m (Replaced <source> with <syntaxhighlight>)
 
(29 intermediate revisions by 15 users not shown)
Line 1: Line 1:
{{LSL_Function/inventory|name|uuid=false|type}}
{{LSL_Function
{{LSL_Function
|inject-2={{Issues/SVC-3670}}{{Issues/SVC-4050}}{{Issues/SVC-6374}}{{LSL_Function/inventory|name|uuid=false}}
|func_id=175|func_sleep=0.0|func_energy=10.0
|func_id=175|func_sleep=0.0|func_energy=10.0
|func=llGetInventoryKey|return_type=key|p1_type=string|p1_name=name
|func=llGetInventoryKey|return_type=key|p1_type=string|p1_name=name
|func_footnote=If '''item''' is not [[llGetInventoryPermMask|copy, mod, trans]] then the return is {{LSL Const|NULL_KEY|key|&quot;00000000-0000-0000-0000-000000000000&quot;|c=Evaluates to false in conditionals just like invalid keys.}}
|func_footnote=If {{LSLP|name}} is not [[llGetInventoryPermMask|copy, mod, trans]] then the return is {{LSL Const|NULL_KEY|key|&quot;00000000-0000-0000-0000-000000000000&quot;|c=Evaluates to false in conditionals just like invalid keys.}}.<br/>Use [[llGetInventoryType]] instead of this function to verify the existence of inventory.
|func_desc
|func_desc
|sort=GetInventoryKey
|sort=GetInventoryKey
|return_text=that is the [[UUID]] of the inventory '''name'''
|return_text=that is the [[UUID]] of the inventory {{LSLP|name}}
|spec
|spec
|caveats
|caveats=*Inventory items are records that usually ''point'' to assets, but they are not the actual assets.
**Multiple inventory items can point to the same asset and return the same key.
**Some newly created inventory entries get default keys until they are edited and saved:
***Newly created notecard entries use [[NULL_KEY]] at present, until they are edited and saved.
***Newly created script entries point to the "[[Hello Avatar]]" script ("d0d40b7c-e32b-3bcb-3346-2be8470093c0" at this writing, not a guaranteed default) until they are edited and saved.
***Most other inventory entries are given unique asset keys at creation time, but this relies on client cooperation and is not guaranteed.
**When an asset is "edited" a new asset key is assigned to the edit. The inventory item used to open the asset for editing is updated with the new asset key.
***No other inventory items that share the original asset are updated with the new asset key.
|constants
|constants
|examples
|examples=
<syntaxhighlight lang="lsl2">
// Put this script in an empty prim, and drag a full-perm texture into the prim's contents to find out its UUID
default
{
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)    // if there has been a change to the prim's contents ...
        {
            string name = llGetInventoryName(INVENTORY_TEXTURE, 0);
            if (name)        // if a texture exists ...
            {
                key uuid = llGetInventoryKey(name);
                if (uuid)    // if the uuid is valid ...
                    llOwnerSay( "The UUID of '" + name + "' is " + (string) uuid);
                else        // texture was not full-perm
                    llOwnerSay( "The UUID of '" + name + "' could not be determined");
            }
        }
    }
}
</syntaxhighlight>
<syntaxhighlight lang="lsl2">string item = "Default";
 
default
{
    state_entry()
    {
        llOwnerSay("Touch to get information about \"" + item + "\".");
    }
 
    touch_start(integer total_number)
    {
        integer type = llGetInventoryType(item);
        integer index = llListFindList([ INVENTORY_NONE,
            INVENTORY_TEXTURE, INVENTORY_SOUND, INVENTORY_LANDMARK, INVENTORY_CLOTHING,
            INVENTORY_OBJECT, INVENTORY_NOTECARD, INVENTORY_SCRIPT, INVENTORY_BODYPART,
            INVENTORY_ANIMATION, INVENTORY_GESTURE], [type]);
        string name = llList2String(["does not exist",
            "texture", "sound", "landmark", "clothing",
            "object", "notecard", "script", "body part",
            "animation", "gesture"], index);
 
        llOwnerSay("Type: " + name);
       
        if(type == INVENTORY_NONE)
            return;
       
        integer owner_perms = llGetInventoryPermMask(item, MASK_OWNER);
        list perms;
        if(owner_perms & PERM_COPY)
            perms += "Copy";
       
        if(owner_perms & PERM_MODIFY)
            perms += "Modify";
       
        if(owner_perms & PERM_TRANSFER)
            perms += "Transfer";
 
        if(owner_perms & PERM_MOVE)
            perms += "Move";
       
        llOwnerSay("Perms: " + llList2CSV(perms));
       
        integer temp = PERM_COPY | PERM_MODIFY | PERM_TRANSFER;
        if((owner_perms & temp) != temp)
            return;
 
        llOwnerSay("Key: " + (string)llGetInventoryKey(item));
    }
}
</syntaxhighlight>
|helpers
|helpers
|also_functions=
|also_functions=
{{LSL DefineRow||[[llGetInventoryName]]|}}
{{LSL DefineRow||[[llGetInventoryAcquireTime]]|Returns the time the item was added to the prim's inventory}}
{{LSL DefineRow||[[llGetInventoryCreator]]|}}
{{LSL DefineRow||[[llGetInventoryName]]|Returns the inventory item's name}}
{{LSL DefineRow||[[llGetInventoryType]]|}}
{{LSL DefineRow||[[llGetInventoryType]]|Tests to see if an inventory item exists and returns its type}}
{{LSL DefineRow||[[llGetInventoryPermMask]]|}}
{{LSL DefineRow||[[llGetInventoryNumber]]|Returns the number of items of a specific type in inventory}}
{{LSL DefineRow||[[llGetInventoryPermMask]]|Returns the inventory item's permissions}}
{{LSL DefineRow||[[llGetInventoryCreator]]|Returns the inventory item's creator}}
|also_events
|also_events
|also_tests
|also_tests
|also_articles
|also_articles
|notes
|notes=*The UUID returned is that of the asset to which the inventory item points, it is not the UUID of the inventory item itself. The assets themselves are immutable (they never change, they are only ever created and deleted); this allows multiple inventory handles to refer to the same asset without having to duplicate the asset. When it appears an asset is being modified, it is saved as a new asset. The consequence of this is that multiple copies of items in inventory all share the same asset UUID.
*It is still possible to inspect the UUID of any animation in inventory by triggering it and using [[llGetAnimationList|llGetAnimationList()]] like so:
<syntaxhighlight lang="lsl2">llStartAnimation("myAnim");
llOwnerSay("myAnim's UUID is " + llList2String(llGetAnimationList(llGetPermissionsKey()), -1));</syntaxhighlight>
|history=
* 0.2 - Introduced during the closed beta period.
* 1.2 - Restricted to full perm inventory items only.
* 1.24 - Objects and scripts no longer return their actual UUID but a hash (i.e. pseudo UUID which is consistent with the object/script) instead. -- {{JIRA|SVC-3670}}
<sup>The preceding version numbers are approximations.</sup>
|cat1=Inventory
|cat1=Inventory
|cat2
|cat2=Key
|cat3
|cat3
|cat4
|cat4
}}
}}

Latest revision as of 08:22, 11 October 2023

Summary

Function: key llGetInventoryKey( string name );
0.0 Forced Delay
10.0 Energy

Returns a key that is the UUID of the inventory name

• string name an item in the inventory of the prim this script is in

If name is not copy, mod, trans then the return is NULL_KEY.
Use llGetInventoryType instead of this function to verify the existence of inventory.

Caveats

  • If name is missing from the prim's inventory then an error is shouted on DEBUG_CHANNEL.
  • Inventory items are records that usually point to assets, but they are not the actual assets.
    • Multiple inventory items can point to the same asset and return the same key.
    • Some newly created inventory entries get default keys until they are edited and saved:
      • Newly created notecard entries use NULL_KEY at present, until they are edited and saved.
      • Newly created script entries point to the "Hello Avatar" script ("d0d40b7c-e32b-3bcb-3346-2be8470093c0" at this writing, not a guaranteed default) until they are edited and saved.
      • Most other inventory entries are given unique asset keys at creation time, but this relies on client cooperation and is not guaranteed.
    • When an asset is "edited" a new asset key is assigned to the edit. The inventory item used to open the asset for editing is updated with the new asset key.
      • No other inventory items that share the original asset are updated with the new asset key.

Examples

// Put this script in an empty prim, and drag a full-perm texture into the prim's contents to find out its UUID
default
{
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)    // if there has been a change to the prim's contents ...
        {
            string name = llGetInventoryName(INVENTORY_TEXTURE, 0);
            if (name)        // if a texture exists ...
            {
                key uuid = llGetInventoryKey(name);
                if (uuid)    // if the uuid is valid ...
                    llOwnerSay( "The UUID of '" + name + "' is " + (string) uuid);
                else         // texture was not full-perm
                    llOwnerSay( "The UUID of '" + name + "' could not be determined");
            }
        }
    }
}
string item = "Default";

default
{
    state_entry()
    {
        llOwnerSay("Touch to get information about \"" + item + "\".");
    }

    touch_start(integer total_number)
    {
        integer type = llGetInventoryType(item);
        integer index = llListFindList([ INVENTORY_NONE, 
            INVENTORY_TEXTURE, INVENTORY_SOUND, INVENTORY_LANDMARK, INVENTORY_CLOTHING, 
            INVENTORY_OBJECT, INVENTORY_NOTECARD, INVENTORY_SCRIPT, INVENTORY_BODYPART, 
            INVENTORY_ANIMATION, INVENTORY_GESTURE], [type]);
        string name = llList2String(["does not exist", 
            "texture", "sound", "landmark", "clothing",
            "object", "notecard", "script", "body part",
            "animation", "gesture"], index);

        llOwnerSay("Type: " + name);
        
        if(type == INVENTORY_NONE)
            return;
        
        integer owner_perms = llGetInventoryPermMask(item, MASK_OWNER);
        list perms;
        if(owner_perms & PERM_COPY)
            perms += "Copy";
        
        if(owner_perms & PERM_MODIFY)
            perms += "Modify";
        
        if(owner_perms & PERM_TRANSFER)
            perms += "Transfer";

        if(owner_perms & PERM_MOVE)
            perms += "Move";
        
        llOwnerSay("Perms: " + llList2CSV(perms));
        
        integer temp = PERM_COPY | PERM_MODIFY | PERM_TRANSFER;
        if((owner_perms & temp) != temp)
            return;

        llOwnerSay("Key: " + (string)llGetInventoryKey(item));
    }
}

Notes

  • The UUID returned is that of the asset to which the inventory item points, it is not the UUID of the inventory item itself. The assets themselves are immutable (they never change, they are only ever created and deleted); this allows multiple inventory handles to refer to the same asset without having to duplicate the asset. When it appears an asset is being modified, it is saved as a new asset. The consequence of this is that multiple copies of items in inventory all share the same asset UUID.
  • It is still possible to inspect the UUID of any animation in inventory by triggering it and using llGetAnimationList() like so:
llStartAnimation("myAnim");
llOwnerSay("myAnim's UUID is " + llList2String(llGetAnimationList(llGetPermissionsKey()), -1));

See Also

Functions

•  llGetInventoryAcquireTime Returns the time the item was added to the prim's inventory
•  llGetInventoryName Returns the inventory item's name
•  llGetInventoryType Tests to see if an inventory item exists and returns its type
•  llGetInventoryNumber Returns the number of items of a specific type in inventory
•  llGetInventoryPermMask Returns the inventory item's permissions
•  llGetInventoryCreator Returns the inventory item's creator

Deep Notes

History

  • 0.2 - Introduced during the closed beta period.
  • 1.2 - Restricted to full perm inventory items only.
  • 1.24 - Objects and scripts no longer return their actual UUID but a hash (i.e. pseudo UUID which is consistent with the object/script) instead. -- SVC-3670
The preceding version numbers are approximations.

Signature

function key llGetInventoryKey( string name );