Jump to content

prim content list question


Vette Jewell
 Share

You are about to reply to a thread that has been inactive for 3544 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm pretty new to scripting and the jargon along with it.  I feel like this should be easy and I just can't figure out how make a list of the objects in a prims inventory. I think part of my problem is that I'm not sure exactly what to look up.  I've looked at several sources, but none of them looked like they would simply create a list.

 

 

Link to comment
Share on other sites

The name of any item in an object's inventory can be retrieved with llGetInventoryName.  All you need to specify is what type of inventory item you are interested in, and which one it is.  Your choices for type are

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
Flag Inventory Type
INVENTORY_OBJECT 6 object
INVENTORY_NOTECARD 7 notecard
INVENTORY_SCRIPT 10 script
INVENTORY_BODYPART 13 body part
INVENTORY_ANIMATION 20 animation
INVENTORY_GESTURE 21 gesture

So you could look for the name of the first notecard in the object's inventory by asking for  llGetInventoryName(INVENTORY_NOTECARD,0);    Remember that lists of anything (including items in inventory) start with item number 0, and that items in inventory are listed alphabetically.

Notice that one of the choice is INVENTORY_ALL, which is handy when you don't want to look for a specific item type.  So llGetInventoryName(INVENTORY_ALL,0) will yield the name of the first item of any kind in inventory.

Therefore, if you want to get the names of all items in inventory, you just have to keep asking that question over and over again, starting with item number 0 and stopping when you have named all items. Something like this will do it:

integer i;while (i < llGetInventoryNumber(INVENTORY_ALL) ){    llSay(0,llGetInventoryName(INVENTORY_ALL,i));    ++i;}

Look at those functions in the LSL wiki and see if that makes sense.

 

 

 

 

 

Link to comment
Share on other sites

So far, you don't have a list, just a repeating llSay statement.  Nothing is being saved.

Study lists in general at http://wiki.secondlife.com/wiki/List

Pay particular attention for now to the section on Adding an Element to a List.  And remember that if you intend to use any variable outside of the local scope, you'll need to make it a global variable.

Link to comment
Share on other sites

I just posted a reply in a thread from a couple days ago which shows how to do this. 

I've copied the snippet and modded it a bit to show you how it's done.  There are three examples, showing local and global storage, in this case a list to store our inventory item names. 

 

  • The first is a local example where the list is temporary, for use within the event or scope it was declared in. 
  • The second is a global example where the list is declared before the default state and accessible throughout the script, but contains repetitive code. 
  • In the third example we expand on the second example and create a custom function for generating an inventory list, since it's used multiple places in our script, eliminating repetitive code.  The function allows you to give it the inventory type, which it uses to generate the list.

 

These three examples are meant to be vehicles for learning.  You will most likely have unique requirements you'll need to work through for your project.  Hopefully this gives you a starting point.  The wiki is your friend.  Everything you need to know to do what you need is there.  The list and inventory functions are a good place to start.

 

// Example using local storage, list can be used within an event only
// or within a scope, whichever the list is declared in

// Drop inventory items in your prim to see the output of this example
// which shows the data in the list separated by commas

default
{
// Something changed, triggers changed event
    changed(integer change)
    {
// Declare a list for use as storage (local)
list inventory_items;

// If inventory is what has changed, generate the list
        if (change & CHANGED_INVENTORY)
        {
            integer counter; // Declare a counter integer to use below
            integer item_count = llGetInventoryNumber(INVENTORY_ALL);
    
            // Loop thru inventory items
            for(counter = 0; counter < item_count; counter++)
            {
                // Store the item in our list
                inventory_items += [llGetInventoryName(INVENTORY_ALL,counter)];
            }
            
// Use the data within the list, in this case we're dumping it to
// the owner in local chat
            llOwnerSay(llDumpList2String(inventory_items,","));            
            
            // List is cleared as soon as the event is exited
            
        }
    }
}

 

// Example using global storage, list can be used anywhere in
// the script

// Drop inventory items in your prim and touch to see the output
// of this example, which shows the data in the list separated
// by commas

// Note the repetitive nature of the list generating code which
// can be found in state_entry and changed events
// We fix this in the third example by making a custom function

// Declare a list for use as storage (global)
list inventory_items;

default
{
state_entry()
{
    integer counter; // Declare a counter integer to use below
        integer item_count = llGetInventoryNumber(INVENTORY_ALL);

        // Loop thru inventory items
        for(counter = 0; counter < item_count; counter++)
        {
            // Store the item in our list
            inventory_items += [llGetInventoryName(INVENTORY_ALL,counter)];
        }
}

    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
inventory_items = []; // Clear our list first
    
            integer counter; // Declare a counter integer to use below
            integer item_count = llGetInventoryNumber(INVENTORY_ALL);
    
            // Loop thru inventory items
            for(counter = 0; counter < item_count; counter++)
            {
                // Store the item in our list
                inventory_items += [llGetInventoryName(INVENTORY_ALL,counter)];
            }
        }
    }
    
    touch_end(integer touches)
    {
        // We can access our list data from anywhere in the script, in this case a touch event
        llOwnerSay(llDumpList2String(inventory_items,","));                    
    }
}

 

// Example using global storage and the versatility of a custom// function to eliminate repetitive code

// See the wiki for more information on custom functions// Drop inventory items in your prim and touch to see the output
// of this example, which shows the data in the list separated
// by commas// Declare a list for use as storage (global)list inventory_items;// Our inventory list getting function, simply pass the type into itget_inventory_list(integer item_type){ inventory_items = []; // Clear our list first integer counter; // Declare a counter integer to use below integer item_count = llGetInventoryNumber(item_type); // Loop thru inventory items for(counter = 0; counter < item_count; counter++) { // Store the item in our list inventory_items += [llGetInventoryName(item_type,counter)]; }}default{ state_entry() { get_inventory_list(INVENTORY_ALL); } changed(integer change) { if (change & CHANGED_INVENTORY) { get_inventory_list(INVENTORY_ALL); } } touch_end(integer touches) { // We can access our list data from anywhere in the script, in this case a touch event

// Dump the list to string using a comma delimiter llOwnerSay("All items in the list: "+llDumpList2String(inventory_items,","));

// Use llList2String to get the first list element
llOwnerSay("First item: "+llList2String(inventory_items,0));


// An example of a for loop to display items one at a time

// Create a counter to count up
integer counter;

// Get the number of items in the list
integer number_of_items = llGetListLength(inventory_items);

// List elements always start at 0
// Loop and display each item in the list, incrementing the counter
// Note how we have to convert counter to a string with typecasting
for(counter = 0; counter < number_of_items; counter++)
{
llOwnerSay("Item #"+(string)(counter+1)+": "+llList2String(inventory_items,counter));
} }}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3544 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...