OsGetInventoryItemKey

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
Line 24: Line 24:
 
         if (ItemKey != NULL_KEY)llSay(PUBLIC_CHANNEL, "Item key is " + osGetInventoryDesc(ItemKey));
 
         if (ItemKey != NULL_KEY)llSay(PUBLIC_CHANNEL, "Item key is " + osGetInventoryDesc(ItemKey));
 
         else llSay(PUBLIC_CHANNEL, "The item key is a NULL_KEY, item not found or owner has no rights ...");
 
         else llSay(PUBLIC_CHANNEL, "The item key is a NULL_KEY, item not found or owner has no rights ...");
 +
    }
 +
}
 +
 +
 +
// Example for osGetLinkInventoryKey
 +
// This script uses the osGetLinkInventoryKey function to fetch the key of a specified inventory item in a specified child prim
 +
 +
// Define the child prim
 +
integer CHILD_PRIM_NUMBER = 2;
 +
// Define the inventory item name
 +
string itemName = "INVENTORY_ITEM_NAME";
 +
 +
// Event handler, that is executed on script start
 +
default
 +
{
 +
    state_entry()
 +
    {
 +
        // Get the key of the inventory item by name in child prim
 +
        key itemUUID = osGetLinkInventoryKey(CHILD_PRIM_NUMBER, itemName);
 +
 +
        // Check if the returned key is not NULL_KEY
 +
        if (itemUUID != NULL_KEY)
 +
        {
 +
            // Output the key to owner chat
 +
            llOwnerSay("UUID of the inventory item '" + itemName + "': " + (string)itemUUID);
 +
        }
 +
        else
 +
        {
 +
            // If the key is NULL_KEY then the item was not found
 +
            llOwnerSay("No inventory item named '" + itemName + "' was found");
 +
        }
 
     }
 
     }
 
}
 
}

Revision as of 10:29, 5 March 2024

key osGetInventoryItemKey(string name)

key osGetLinkInventoryKey(integer linkNumber, string name)

Returns id(key) of a inventory item within a prim inventory.
If name is not unique result maybe unpredictable.
Note that unlike this function, llGetInventoryKey does not return the item ID but the ID of its asset.
Returns NULL_KEY if the item is not found or Owner has no rights
Threat Level This function does not do a threat level check
Permissions Script owner needs modify, copy and transfer rights
Extra Delay 0 seconds
Example(s)
//
// osGetInventoryItemKey Script Exemple
// Author: Ubit
//
 
default
{
    state_entry()
    {
        llSay(PUBLIC_CHANNEL, "Touch me to see osGetInventoryItemKey usage.");
    }
 
    touch_start(integer number)
    {
        key ItemKey = osGetInventoryItemKey("MyItemName");
        if (ItemKey != NULL_KEY)llSay(PUBLIC_CHANNEL, "Item key is " + osGetInventoryDesc(ItemKey));
        else llSay(PUBLIC_CHANNEL, "The item key is a NULL_KEY, item not found or owner has no rights ...");
    }
}
 
 
// Example for osGetLinkInventoryKey
// This script uses the osGetLinkInventoryKey function to fetch the key of a specified inventory item in a specified child prim
 
// Define the child prim
integer CHILD_PRIM_NUMBER = 2;
// Define the inventory item name
string itemName = "INVENTORY_ITEM_NAME";
 
// Event handler, that is executed on script start
default
{
    state_entry()
    {
        // Get the key of the inventory item by name in child prim
        key itemUUID = osGetLinkInventoryKey(CHILD_PRIM_NUMBER, itemName);
 
        // Check if the returned key is not NULL_KEY
        if (itemUUID != NULL_KEY)
        {
            // Output the key to owner chat
            llOwnerSay("UUID of the inventory item '" + itemName + "': " + (string)itemUUID);
        }
        else
        {
            // If the key is NULL_KEY then the item was not found
            llOwnerSay("No inventory item named '" + itemName + "' was found");
        }
    }
}
Notes
This function was added in 0.9.1.0 Dev

Implemented August, 16 2019


See Also:

Personal tools
General
About This Wiki