Difference between revisions of "LlRemoveInventory"

From Second Life Wiki
Jump to navigation Jump to search
m (added how to use userfunction)
(Removed superfluous line from 2nd example index = llGetInventoryNumber(INVENTORY_ALL); Removed meaningless comment. Avoid defining a string each iteration)
Line 28: Line 28:
{
{
     string thisScript = llGetScriptName();
     string thisScript = llGetScriptName();
 
     string inventoryItemName;
     // while loops are faster
    // --index; faster than index--;


     integer index = llGetInventoryNumber(INVENTORY_ALL);
     integer index = llGetInventoryNumber(INVENTORY_ALL);
     while (index)
     while (index)
     {
     {
         --index;
         --index;       // (faster than index--;)


         string inventoryItemName = llGetInventoryName(INVENTORY_ALL, index);
         inventoryItemName = llGetInventoryName(INVENTORY_ALL, index);


         if (inventoryItemName != thisScript)
         if (inventoryItemName != thisScript)  
        {
             llRemoveInventory(inventoryItemName);    
             llRemoveInventory(inventoryItemName);
            index = llGetInventoryNumber(INVENTORY_ALL);
        }
     }
     }
}
}

Revision as of 13:48, 13 December 2012

Summary

Function: llRemoveInventory( string item );

Remove the named inventory item

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

Caveats

  • If item is missing from the prim's inventory then an error is shouted on DEBUG_CHANNEL.
  • If the current script is removed it will continue to run for a short period of time after this call.
  • With multiple executions an llSleep(0.1) after llRemoveInventory will allow edit window contents to refresh correctly and avoid errors on phantom contents.

Important Issues

~ All Issues ~ Search JIRA for related Bugs
   CHANGED_INVENTORY not triggered by llRemoveInventory()

Examples

<lsl> // Remove the current script from the object

default {

   state_entry()
   {
       llRemoveInventory(llGetScriptName());
   }

} </lsl> <lsl> // user-function to include in your script // deletes all other contents of any type except the script itself delete_all_other_contents() {

   string thisScript = llGetScriptName();
   string inventoryItemName;
   integer index = llGetInventoryNumber(INVENTORY_ALL);
   while (index)
   {
       --index;        // (faster than index--;)
       inventoryItemName = llGetInventoryName(INVENTORY_ALL, index);
       if (inventoryItemName != thisScript)   
           llRemoveInventory(inventoryItemName);     
   }

}

default {

   state_entry()
   {
       delete_all_other_contents();
   }

}

</lsl>

Deep Notes

All Issues

~ Search JIRA for related Issues
   CHANGED_INVENTORY not triggered by llRemoveInventory()

Signature

function void llRemoveInventory( string item );