Difference between revisions of "LlGetInventoryName"

From Second Life Wiki
Jump to navigation Jump to search
m
m (Replaced <source> with <syntaxhighlight>)
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|inject-2={{LSL Function/negative_index|false|number}}
|inject-3={{LSL Function/negative_index|false|number}}
|func_id=147|func_sleep=0.0|func_energy=10.0
|func_id=147|func_sleep=0.0|func_energy=10.0
|func=llGetInventoryName|return_type=string
|func=llGetInventoryName|return_type=string
|p1_type=integer|p1_name=type|p1_desc=INVENTORY_* flag
|p1_type=integer|p1_name=type|p1_desc=INVENTORY_* flag
|p2_type=integer|p2_name=number|p2_desc=Beginning from 0
|p2_type=integer|p2_name=number|p2_desc=Beginning from 0
|func_footnote=Inventory items are sorted in alphabetical order (not chronological order).
|func_footnote=
Inventory items are sorted in alphabetical order (not chronological order).
|func_desc
|func_desc
|return_text=that is the name of the inventory item {{LSLP|number}} of {{LSLP|type}}. Returns an empty string if no item of the specified type is found in the prim's inventory (or there are less than or equal to {{LSLP|number}} items of the type).
|return_text=that is the name of the inventory item {{LSLP|number}} of {{LSLP|type}}. Returns an empty string if no item of the specified type is found in the prim's inventory (or there are less than or equal to {{LSLP|number}} items of the type).
Line 12: Line 13:
|constants={{LSL Constants Inventory}}
|constants={{LSL Constants Inventory}}
|examples======Box Unpacker=====
|examples======Box Unpacker=====
<lsl>
<syntaxhighlight lang="lsl2">
// script created by SpiritWolf Chikuwa
// Give all prim contents to anyone touching this object,
//  minor changes by Strife Onizuka to speed things up
// But don't give this script itself.
//
//  This script is public domain.
//  You can copy, modify or transfer.
// Please, do not resell this script but give it full perms for free.
//  Please keep this header intact.
//
//  Minor changes: (insert your name here and delete this comment if you do any mod of this script, thank you)
//
// Script start here:
 
list listOfInventoryItems;
 
update_inventory_items_list()
{
//  empty the list
    listOfInventoryItems = [];
 
//  get the total number of items
    integer numberOfItems = llGetInventoryNumber(INVENTORY_ALL);
 
//  get names of inventory items
//  index is 0 to (total - 1)
    integer index;
    do
    {
        listOfInventoryItems += [llGetInventoryName(INVENTORY_ALL, index)];
    }
    while (++index < numberOfItems);
}


default
default
{
{
    changed(integer change)
    {
      if (change & CHANGED_INVENTORY)
          update_inventory_items_list();
    }
    state_entry()
    {
        update_inventory_items_list();
    }
     touch_start(integer num_detected)
     touch_start(integer num_detected)
     {
     {
         key avatarKey = llDetectedKey(0);
         list    InventoryList;
         string folderName = llGetObjectName();
        integer count = llGetInventoryNumber(INVENTORY_ALL); // Count of all items in prim's contents
 
         string ItemName;
         llGiveInventoryList(avatarKey, folderName, listOfInventoryItems);
        while (count--)
        {
            ItemName = llGetInventoryName(INVENTORY_ALL, count);
            if (ItemName != llGetScriptName()
                InventoryList += ItemName;   // add all contents except this script, to a list
        }
        // Give all the items to the toucher, in a folder named as per this prim's name
         llGiveInventoryList(llDetectedKey(0), llGetObjectName(), InventoryList);
     }
     }
}
}
</lsl>
</syntaxhighlight>
|helpers
|helpers
|also_functions=
|also_functions=
{{LSL DefineRow||[[llGetInventoryAcquireTime]]|Returns the time the item was added to the prim's inventory}}
{{LSL DefineRow||[[llGetInventoryNumber]]|Returns the number of items of a specific type in inventory}}
{{LSL DefineRow||[[llGetInventoryNumber]]|Returns the number of items of a specific type in inventory}}
{{LSL DefineRow||[[llGetInventoryType]]|Tests to see if an inventory item exists and returns its type.}}
{{LSL DefineRow||[[llGetInventoryType]]|Tests to see if an inventory item exists and returns its type.}}

Latest revision as of 10:03, 9 March 2023

Summary

Function: string llGetInventoryName( integer type, integer number );

Returns a string that is the name of the inventory item number of type. Returns an empty string if no item of the specified type is found in the prim's inventory (or there are less than or equal to number items of the type).

• integer type INVENTORY_* flag
• integer number Beginning from 0

number does not support negative indexes. Inventory items are sorted in alphabetical order (not chronological order).

Flag Inventory Type
INVENTORY_NONE -1 Item does not exist.
INVENTORY_ALL Any inventory type.
INVENTORY_TEXTURE 0 texture
INVENTORY_SOUND 1 sound
INVENTORY_LANDMARK 3 landmark
INVENTORY_CLOTHING 5 clothing
INVENTORY_OBJECT 6 object
Flag Inventory Type
INVENTORY_NOTECARD 7 notecard
INVENTORY_SCRIPT 10 script
INVENTORY_BODYPART 13 body part
INVENTORY_ANIMATION 20 animation
INVENTORY_GESTURE 21 gesture
INVENTORY_SETTING 56 setting
INVENTORY_MATERIAL 57 material

Caveats

  • If number is out of bounds the script continues to execute without an error message.
All Issues ~ Search JIRA for related Bugs

Examples

Box Unpacker
// Give all prim contents to anyone touching this object,
// But don't give this script itself.

default
{
    touch_start(integer num_detected)
    {
        list    InventoryList;
        integer count = llGetInventoryNumber(INVENTORY_ALL);  // Count of all items in prim's contents
        string  ItemName;
        while (count--)
        {
            ItemName = llGetInventoryName(INVENTORY_ALL, count);
            if (ItemName != llGetScriptName() )  
                InventoryList += ItemName;   // add all contents except this script, to a list
        }
        // Give all the items to the toucher, in a folder named as per this prim's name
        llGiveInventoryList(llDetectedKey(0), llGetObjectName(), InventoryList);
    }
}

Notes

The maximum number of characters for an object inventory item is currently 63 characters.

See Also

Functions

•  llGetInventoryAcquireTime Returns the time the item was added to the prim's inventory
•  llGetInventoryNumber Returns the number of items of a specific type in inventory
•  llGetInventoryType Tests to see if an inventory item exists and returns its type.
•  llGetInventoryCreator Returns the inventory item's creator
•  llGetInventoryPermMask Returns the inventory item's permissions
•  llGetInventoryKey Returns the inventory item's UUID (if full perm)

Deep Notes

Search JIRA for related Issues

Tests

•  llGiveInventory_All_Test

Signature

function string llGetInventoryName( integer type, integer number );