List Inventory

From libopenmetaverse - libomv - Developer Wiki

Jump to: navigation, search



This example shows how to make your bot search through its inventory, the information that the snippet provides can be used for inventory management (i.e. deleting items, giving items etc), appearance management (e.g. attaching items), etc.


The following prerequisites are required in order for you to make your bot illiterate through its inventory

Real World

  • This tutorial assumes that you were able to successfully build libsecondlife! If you have not compiled libsl, please follow the instructions on the Getting Started wikipage.
  • Also, if you have no experience with the C# (c-sharp) programming language, I highly recommend that you stop now and please follow the list of links to csharp tutorials located here.

The Code

Note: We are assuming that our main "GridClient" instance variable is named "Client." If you have a different name for this variable, please substitute the name accordingly

static void ListObjectsFolder()
            //initialize our list to store the folder contents
            UUID inventoryItems;
            //make a string array to put our folder names in.
            String[] SearchFolders = { "" };
            //Next we grab a full copy of the entire inventory and get it stored into the Inventory Manager
            Client.Inventory.RequestFolderContents(Client.Inventory.Store.RootFolder.UUID, Client.Self.AgentID, true, true, InventorySortOrder.ByDate);
            //Next we want to step through the directory structure until we get to the item.
            SearchFolders[0] = "Objects";
            //Now we can grab the details of that folder and store it to our list.
            inventoryItems = client.Inventory.FindObjectByPath(client.Inventory.Store.RootFolder.UUID, client.Self.AgentID, SearchFolders[0], 1000);
	    // Create the list which we can use to iliterate through
            List<InventoryBase> myObjects = client.Inventory.FolderContents(inventoryItems, client.Self.AgentID, true, true, InventorySortOrder.ByName, 1000);
            foreach (InventoryBase item in myObjects)
		// Illiterate through our list of items and print them to the console
                Console.WriteLine("[Inventory Item] Name: " + item.Name + " <==> " + item.UUID.ToString());
		// Code that processes each item goes here