Trouble llSleeping - advise please

Creating scripts
Post Reply
User avatar
Shandon Loring
Posts: 1341
Joined: Sat Oct 26, 2013 3:25 am
Has thanked: 961 times
Been thanked: 1581 times
Contact:

Trouble llSleeping - advise please

Post by Shandon Loring »

So I'm lucky most days to make a working script that says 'Hello Avatar!', hence I defer to y'all..
I understand that most scripters hate the llSleep command. In the following example script, could anyone suggest some better way to perform the multiple pauses in the execution of this script?
(of course this is not a real script, and yes it is an endless loop as written, but it would be in a temp rez object so i'm not really concerned about the endless bit)
Thanks All!

-----------------------

integer on;

default
{
state_entry()
{
llSetTimerEvent(.05);
}

timer()

{
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();
llSleep (.03);
llPerform-Some-Function();

}
}
Last edited by Shandon Loring on Sun Jan 22, 2023 7:01 am, edited 1 time in total.
These users thanked the author Shandon Loring for the post:
Christine Nyn
User avatar
Ilan Tochner
Posts: 6503
Joined: Sun Dec 23, 2012 8:44 am
Has thanked: 4942 times
Been thanked: 4454 times
Contact:

Re: Attn: llSleep Haters - advise please

Post by Ilan Tochner »

Hi Shandon,

llsleep should be avoided because it can prevent other scripts from being run. See: http://opensimulator.org/pipermail/open ... 10792.html
These users thanked the author Ilan Tochner for the post (total 3):
Shandon LoringChristine NynSelby Evans
User avatar
Shandon Loring
Posts: 1341
Joined: Sat Oct 26, 2013 3:25 am
Has thanked: 961 times
Been thanked: 1581 times
Contact:

Re: Attn: llSleep Haters - advise please

Post by Shandon Loring »

Thank you Ilan,
Like Nicky Perian in the article you reference, more what I'm asking is a suggested way to rewrite the example script I provided.
Anyone?

Thanks all!
:D
These users thanked the author Shandon Loring for the post (total 2):
Ilan TochnerChristine Nyn
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Trouble llSleeping - advise please

Post by Graham Mills »

I'm an intermediate-level scripter at best but I think the following does what you specified using llOwnerSay instead of llPerform etc. It also avoids continuous operation.

Code: Select all

integer LOOP = 0;
integer MAX = 14;

default
{
    state_entry()
    {
        if (LOOP == 0)
        {
            llSetTimerEvent(0.5);
        }
        else if (LOOP < MAX)
        {
            llSetTimerEvent(0.03);
        }
        else
        {
            llSetTimerEvent(0.0);
        }
    }
    
    timer()
    {
       state doLoop;
    }
}

state doLoop
{
    state_entry()
    {
        llOwnerSay(">>"+(string)LOOP);
        LOOP++;
        state default;
    }
}
These users thanked the author Graham Mills for the post (total 3):
Ilan TochnerChristine NynShandon Loring
User avatar
Christine Nyn
Posts: 71
Joined: Sat Mar 07, 2020 10:20 pm
Has thanked: 218 times
Been thanked: 126 times

Re: Trouble llSleeping - advise please

Post by Christine Nyn »

Using the timer event as Graham has done is the way to go when restructuring a script to avoid the use of llSleep. The only downside to that is that you couldn't get the 0.03 delay you put in your original example since the shortest interval available on a Kitely timer is 0.5 seconds (or was when last I checked).

The main reason for avoiding llSleep is that OpenSim doesn't have many threads running simultaneously to handle all the scripts that are running on a region and llSleep() simply hangs on to a thread while doing absolutely nothing. The timer event gives back the thread to the general pool until the timer fires. This has the effect that if several scripts are running which are using llSleep they can starve all other scripts in the region of the chance to run, effectively bringing everything to a halt.
These users thanked the author Christine Nyn for the post (total 4):
Ilan TochnerShandon LoringGraham MillsSelby Evans
User avatar
Shandon Loring
Posts: 1341
Joined: Sat Oct 26, 2013 3:25 am
Has thanked: 961 times
Been thanked: 1581 times
Contact:

Re: Trouble llSleeping - advise please

Post by Shandon Loring »

Thank you all for insight and advice!
These users thanked the author Shandon Loring for the post:
Graham Mills
Post Reply