Difference between revisions of "Resetting Scripts in a Large Build"

From Second Life Wiki
Jump to navigation Jump to search
(first draft)
 
m (→‎Random Staggered Reset: fixed an obvious typo)
 
(6 intermediate revisions by 3 users not shown)
Line 9: Line 9:
(or other event)
(or other event)


<lsl>
<source lang="lsl2">
 
default
default
{
{
state_entry()
    changed(integer change)
{
    {
//setup and do stuff
        if (change & CHANGED_REGION_START)
}
        {
            llOwnerSay("The regions has just restarted, resetting the script.");
            llResetScript();
        }
    }


changed(integer change)
    state_entry()
{
    {
if (change & CHANGED_REGION_START)
        //  setup and do stuff
{
    }
llOwnerSay("The regions has just restarted, resetting the script.");
llResetScript();
}
}
}
}
 
</source>
</lsl>


=Listener - restart on command=
=Listener - restart on command=
Line 34: Line 32:
Listen for instruction and restart script.
Listen for instruction and restart script.


<lsl>
<source lang="lsl2">
//  some random negative number
integer chatChannel = -1324628;
 
//  could consider using a random string for the command to obscure the function
string chatCommand = "reset";


default
default
{
{
//  this script sends the command to reset the other scripts to reset.
//  change to use any trigger event that is suitable.


// this script sends the command to reset the other scripts to reset.
    touch(integer num_detected)
// change to use any trigger event that is suitable.
    {
 
        llRegionSay(chatChannel, chatCommand);// (3)
integer channel = -1324628; // some random negative number
    }
string command = "reset"; // could consider using a random string for the command to obscure the function
 
touch(integer num_detected)
{
llRegionsSay(channel, command); // (3)
}
 
}
}
</source>


</lsl>
<source lang="lsl2">
//  some random negative number
integer chatChannel = -1324628;


<lsl>
//  could consider using a random string for the command to obscure the function
string chatCommand = "reset";


default
default
{
{
//  insert the listen into your scripts that need to reset on command


//insert the lisetn into your scripts that need to reset on command
    state_entry()
 
    {
integer channel = -1324628; //some random negative number
    // setup and do stuff
string command = "reset"; //could consider using a random string for the command to obscure the function
        llListen(chatChannel, "", NULL_KEY, chatCommand);
 
    }
state_entry()
{
//setup and do stuff
llListen(channel, "", NULL_KEY, command);
}
 
listen(integer channel, string name, key id, string message)
{
if (message == command) llResetScript();
}


    listen(integer channel, string name, key id, string message)
    {
        if (message == chatCommand)
            llResetScript();
    }
}
}
 
</source>
</lsl>


=Random Staggered Reset=
=Random Staggered Reset=
Line 83: Line 80:
Script load on the sim may be a concern, if so you could use a random timer in the target script to stagger the reset as follows:
Script load on the sim may be a concern, if so you could use a random timer in the target script to stagger the reset as follows:


<lsl>
<source lang="lsl2">
//  some random negative number
integer chatChannel = -1324628;
 
//  could consider using a random string for the command to obscure the function
string chatCommand = "reset";


default
default
{
{
//  insert the listen into your scripts that need to reset on command


//insert the listen into your scripts that need to reset on command
    state_entry()
    {
    //setup and do stuff
    llListen(chatChannel, "", NULL_KEY, chatCommand);
    }


integer channel = -1324628; //some random negative number
    listen(integer channel, string name, key id, string message)
string command = "reset"; //could consider using a random string for the command to obscure the function
    {
 
        if (message == chatCommand)
state_entry()
        {
{
            //random timer within [0.0, 60.0)
//setup and do stuff
            llSetTimerEvent( llFrand(60.0) );
llListen(channel, "", NULL_KEY, command);
        }
}
    }
 
listen(integer channel, string name, key id, string message)
{
if (message == command) llSetTimer(llFrand(60)); //random timer within 60 seconds
}
 
timer()
{
llResetScript();
}


    timer()
    {
        llResetScript();
    }
}
}
</source>


</lsl>


If you need to stagger the resets, perhaps because the order the scripts start is important, use different commands with appropriate pauses between start commands, such as:


If you need to stagger the resets, perhaps because the order the sxripts start is imortant, use different commands with appropriate pauses between start commands, such as:
<source lang="lsl2">
//  some random negative number
integer chatChannel = -1324628;


<lsl>
//  could consider using a random string for the command to obscure the function. "reset3" will trigger after 15 seconds.
string chatCommand = "reset3";


default
default
{
{
    state_entry()
    {
    //  setup and do stuff
        llListen(chatChannel, "", NULL_KEY, chatCommand);
    }


integer channel = -1324628; //some random negative number
    listen(integer channel, string name, key id, string message)
string command = "reset3"; //could consider using a random string for the command to obscure the function. "reset3" will trigger after 15 seconds.
    {
 
        if (message == chatCommand) llResetScript();
state_entry()
    }
{
//setup and do stuff
llListen(channel, "", NULL_KEY, command);
}
 
listen(integer channel, string name, key id, string message)
{
if (message == command) llResetScript();
}
 
}
}
 
</source>
</lsl>


----
----
Return to [[Good_Building_Practices]]
Return to [[Good_Building_Practices]]

Latest revision as of 00:22, 15 March 2015

If you have a complex build, perhaps sim wide and you need to reset all of the scripts, there isn't an easy way to do this, say from from parcel properties or the region tools.

This presents a few startegies for providing this ability but it does require some forethought.

Region Restart

Detect region restart and restart script.

(or other event)

default
{
    changed(integer change)
    {
        if (change & CHANGED_REGION_START) 
        {
            llOwnerSay("The regions has just restarted, resetting the script.");
            llResetScript();
        }
    }

    state_entry()
    {
        //  setup and do stuff
    }
}

Listener - restart on command

Listen for instruction and restart script.

//  some random negative number
integer chatChannel = -1324628;

//  could consider using a random string for the command to obscure the function
string chatCommand = "reset";

default
{
//  this script sends the command to reset the other scripts to reset.
//  change to use any trigger event that is suitable.

    touch(integer num_detected)
    {
        llRegionSay(chatChannel, chatCommand);//  (3)
    }
}
//  some random negative number
integer chatChannel = -1324628;

//  could consider using a random string for the command to obscure the function
string chatCommand = "reset";

default
{
//  insert the listen into your scripts that need to reset on command

    state_entry()
    {
    //  setup and do stuff
        llListen(chatChannel, "", NULL_KEY, chatCommand);
    }

    listen(integer channel, string name, key id, string message)
    {
        if (message == chatCommand)
            llResetScript();
    }
}

Random Staggered Reset

Script load on the sim may be a concern, if so you could use a random timer in the target script to stagger the reset as follows:

//  some random negative number
integer chatChannel = -1324628;

//  could consider using a random string for the command to obscure the function
string chatCommand = "reset";

default
{
//  insert the listen into your scripts that need to reset on command

    state_entry()
    {
    //setup and do stuff
    llListen(chatChannel, "", NULL_KEY, chatCommand);
    }

    listen(integer channel, string name, key id, string message)
    {
        if (message == chatCommand)
        {
            //random timer within [0.0, 60.0)
            llSetTimerEvent( llFrand(60.0) );
        }
    }

    timer()
    {
        llResetScript();
    }
}


If you need to stagger the resets, perhaps because the order the scripts start is important, use different commands with appropriate pauses between start commands, such as:

//  some random negative number
integer chatChannel = -1324628;

//  could consider using a random string for the command to obscure the function. "reset3" will trigger after 15 seconds.
string chatCommand = "reset3";

default
{
    state_entry()
    {
    //  setup and do stuff
        llListen(chatChannel, "", NULL_KEY, chatCommand);
    }

    listen(integer channel, string name, key id, string message)
    {
        if (message == chatCommand) llResetScript();
    }
}

Return to Good_Building_Practices