Difference between revisions of "Remove all scripts from a linkset"

From Second Life Wiki
Jump to navigation Jump to search
m (a few minor readability changes)
m (... and forgot to add the "mandatory" LSL Header :P)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
This simple script removes all scripts contained in a linkset. I had found one on the Internet but for an unknown reason, it moves the linkset (see [http://community.secondlife.com/t5/LSL-Library/Script-Remover-for-Linksets/td-p/721141]) ?! This one is simple, and works for attachments and rezzed objects. Just drop the script in the linkset (so in the root prim). If the linkset is one single prim, there is nothing else to do. Otherwise, when the script tells you that it is ready, unrez/re-rez the object and set all scripts to running using the menu of the viewer. That's all. An hovertext shows the number of remaining prims to be cleaned up. This script is very useful for example for Firestorm's users: indeed when this page is being written down, the feature is still missing in Firestorm.
{{LSL Header}}


<lsl>
This simple script removes all scripts contained in a linkset. I had found one on the Internet but for an unknown reason, it moves the linkset (see [https://community.secondlife.com/forums/topic/32874-script-remover-for-linksets/ this thread on the forums]) ?! This one is simple and works for attachments and rezzed objects. Just drop the script in the linkset (i.e., into the root prim). If the linkset is one single prim, there is nothing else to do. Otherwise, when the script tells you that it is ready, unrez/re-rez the object and set all scripts to running using the menu of the viewer. That's all. An hovertext shows the number of remaining prims to be cleaned up. This script is very useful for example for Firestorm users: indeed, at the time of writing this down<ref>February 2012</ref>, the feature is still missing in Firestorm.
//  Script eraser by Dahlia Orfan (2012)  
 
<syntaxhighlight lang="lsl2">
//  Script eraser by Dahlia Orfan (2012)
//  Drop this script in a linkset (rezzed on the ground or attachment)
//  Drop this script in a linkset (rezzed on the ground or attachment)
//  When the script tells that it is ready, unrez and rerez the linkset
//  When the script tells that it is ready, unrez and rerez the linkset
Line 19: Line 21:
     string scriptName;
     string scriptName;


//  start with last script which has the index (numberOfScripts - 1)
    //  start with last script which has the index (numberOfScripts - 1)
     do
     do
     {
     {
Line 26: Line 28:


         if (scriptName != thisScript)
         if (scriptName != thisScript)
          llRemoveInventory(scriptName);
            llRemoveInventory(scriptName);
     }
     }
     while (index);
     while (index);


//  at last remove this script
    //  at last remove this script
     llRemoveInventory(thisScript);
     llRemoveInventory(thisScript);
}
}
Line 38: Line 40:
     state_entry()
     state_entry()
     {
     {
         string ownerMD5string = llMD5String((string)llGetOwner(), 31415);
         //  set an ident number code
 
         DELETE = (integer) ("0x" + (string) llGetOwner() );
    //  set an ident number code
         DELETE = (integer)("0x" + llGetSubString(ownerMD5string, 0, 6));
 
         integer link = llGetLinkNumber();
         integer link = llGetLinkNumber();


    //  the root prim has link number 0 for single prim objects and 1 for linksets
        //  the root prim has link number 0 for single prim objects and 1 for linksets
         if (link <= 1)
         if (link < 2)
         {
         {
             prims = llGetNumberOfPrims();
             prims = llGetObjectPrimCount(llGetKey() );       // Get number of prims excluding seated avatars


        //  do not count seated agents
             //  if single prim, else linkset
             if(1 < prims)
                while(llGetAgentSize(llGetLinkKey(prims)))
                    --prims;
 
        //  if single prim, else linkset
             if (prims == 1)
             if (prims == 1)
            {
                llSay(0, "Done removing scripts.");
                 remove_scripts();
                 remove_scripts();
            }
             else
             else
             {
             {
Line 66: Line 63:
                     --n;
                     --n;
                 }
                 }
            //  PUBLIC_CHANNEL has the integer value 0
                 llSay(0, "Please take this object back to your inventory and "
                 llSay(PUBLIC_CHANNEL, "Please take this object back to your inventory and "
                     + "rez it again. Then edit the object (ctrl+3), go to the menu at the "
                     + "rez it again. Then edit the object (ctrl+3), go to the menu at the "
                     + "top of your viewer and select BUILD > SCRIPTS > SET SCRIPTS TO RUNNING.");
                     + "top of your viewer and select BUILD > SCRIPTS > SET SCRIPTS TO RUNNING.");
Line 81: Line 77:
     link_message(integer sender_num, integer num, string str, key id)
     link_message(integer sender_num, integer num, string str, key id)
     {
     {
    //  if the received linkmessage contains the ident number code previously stored...
        //  if the received linkmessage contains the ident number code previously stored...
         if (num == DELETE)
         if (num == DELETE)
         {
         {
             --prims;
             --prims;
             if (prims == 1)
             if (prims == 1)
            {
                llSay(0, "Done removing scripts.");
                 remove_scripts();
                 remove_scripts();
            }
         }
         }
     }
     }
}
}
</lsl>
</syntaxhighlight>
 
=== Notes ===
{{References}}

Latest revision as of 13:03, 5 December 2023

This simple script removes all scripts contained in a linkset. I had found one on the Internet but for an unknown reason, it moves the linkset (see this thread on the forums) ?! This one is simple and works for attachments and rezzed objects. Just drop the script in the linkset (i.e., into the root prim). If the linkset is one single prim, there is nothing else to do. Otherwise, when the script tells you that it is ready, unrez/re-rez the object and set all scripts to running using the menu of the viewer. That's all. An hovertext shows the number of remaining prims to be cleaned up. This script is very useful for example for Firestorm users: indeed, at the time of writing this down[1], the feature is still missing in Firestorm.

//  Script eraser by Dahlia Orfan (2012)
//  Drop this script in a linkset (rezzed on the ground or attachment)
//  When the script tells that it is ready, unrez and rerez the linkset
//  Set all scripts to running using the menu of the viewer
//  Wait until it is done.   http://pastebin.com/gqi7mKFE

integer prims;
integer DELETE;

//  remove all other scripts, then this one
remove_scripts()
{
    string thisScript = llGetScriptName();

    integer index = llGetInventoryNumber(INVENTORY_SCRIPT);
    string scriptName;

    //  start with last script which has the index (numberOfScripts - 1)
    do
    {
        --index;
        scriptName = llGetInventoryName(INVENTORY_SCRIPT, index);

        if (scriptName != thisScript)
            llRemoveInventory(scriptName);
    }
    while (index);

    //  at last remove this script
    llRemoveInventory(thisScript);
}

default
{
    state_entry()
    {
        //  set an ident number code
        DELETE = (integer) ("0x" + (string) llGetOwner() );
        integer link = llGetLinkNumber();

        //  the root prim has link number 0 for single prim objects and 1 for linksets
        if (link < 2)
        {
            prims = llGetObjectPrimCount(llGetKey() );        // Get number of prims excluding seated avatars

            //  if single prim, else linkset
            if (prims == 1)
            {
                llSay(0, "Done removing scripts.");
                remove_scripts();
            }
            else
            {
                integer n = prims;
                while(n > 1)
                {
                    llGiveInventory(llGetLinkKey(n), llGetScriptName());
                    --n;
                }
                llSay(0, "Please take this object back to your inventory and "
                    + "rez it again. Then edit the object (ctrl+3), go to the menu at the "
                    + "top of your viewer and select BUILD > SCRIPTS > SET SCRIPTS TO RUNNING.");
            }
        }
        else//  not the root prim
        {
            llMessageLinked(LINK_ROOT, DELETE, "", NULL_KEY);
            remove_scripts();
        }
    }

    link_message(integer sender_num, integer num, string str, key id)
    {
        //  if the received linkmessage contains the ident number code previously stored...
        if (num == DELETE)
        {
            --prims;
            if (prims == 1)
            {
                llSay(0, "Done removing scripts.");
                remove_scripts();
            }
        }
    }
}

Notes

  1. February 2012