Difference between revisions of "WhoAddedWhat"

From Second Life Wiki
Jump to navigation Jump to search
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
To enable you to tell what has been added to a script on CHANGED_ALLOWED_DROP events you can use the following code:
To enable you to tell what has been added to a script in the event of '''CHANGED_ALLOWED_DROP''' you can use the following code:


<lsl>list content[]; // a list of all items already added to the object
<source lang="lsl2">// Scripted by Laronzo Fitzgerald


if (change & CHANGED_ALLOWED_DROP || CHANGED_INVENTORY)
list content[]; // a list of all items already added to the object
 
if (change & (CHANGED_ALLOWED_DROP | CHANGED_INVENTORY))
{
{
            integer n = llGetInventoryNumber(INVENTORY_ALL);             
    integer n = llGetInventoryNumber(INVENTORY_ALL);             
 
    while(n)
    {
        integer valid = llGetListLength(contents);
        if(valid != 0)
        {
              string added = llGetInventoryName(INVENTORY_ALL, --n);
              integer index = llListFindList(content, [added]);
              if(!(~index))
              {
                  integer type = llGetInventoryType(added);
 
                  if(type != 10 && (string)type != "") // don't add the object's script to the list of items!
                  {
        content += added; // add the new item to the checklist of inventory items
                        // Do anything else you want related to the new item here
                  }
              }
        }
    }
}</source>
 
(This code contains an obvious bug: if "content" is empty, then "if (valid != 0)" is not true, and the "n" in "while(n)" doesn't get changed -> endless loop.)
(Weird code: if "content" is empty (which is always the case at startup), then nothing can get added to "content".)
(Also: the var is named "content", but also 1 time "contents" is used.)


            while(n)
[[llAllowInventoryDrop]]
            {
                integer valid = llGetListLength(contents);
                if(valid != 0)
                {
                    string added = llGetInventoryName(INVENTORY_ALL, --n);
                    integer index = llListFindList(contents, [added]);
                    if(!(~index))
                    {
                        if(type != 10 && (string)type != "") // don't add the object's script to the list of items!
                        {
    content += added; // add the new item to the checklist of inventory items
                        }
    }
                }
            }
}</lsl>

Latest revision as of 19:17, 11 April 2015

To enable you to tell what has been added to a script in the event of CHANGED_ALLOWED_DROP you can use the following code:

// Scripted by Laronzo Fitzgerald

list content[]; // a list of all items already added to the object

if (change & (CHANGED_ALLOWED_DROP | CHANGED_INVENTORY))
{
    integer n = llGetInventoryNumber(INVENTORY_ALL);            

    while(n)
    {
         integer valid = llGetListLength(contents);
         if(valid != 0)
         {
              string added = llGetInventoryName(INVENTORY_ALL, --n);
              integer index = llListFindList(content, [added]);
              if(!(~index))
              {
                   integer type = llGetInventoryType(added);

                   if(type != 10 && (string)type != "") // don't add the object's script to the list of items!
                   {
		        content += added; // add the new item to the checklist of inventory items
                        // Do anything else you want related to the new item here
                   }
              }
         }
    }
}

(This code contains an obvious bug: if "content" is empty, then "if (valid != 0)" is not true, and the "n" in "while(n)" doesn't get changed -> endless loop.) (Weird code: if "content" is empty (which is always the case at startup), then nothing can get added to "content".) (Also: the var is named "content", but also 1 time "contents" is used.)

llAllowInventoryDrop