Page 1 of 1

Trouble llSleeping - advise please

Posted: Sun Jan 22, 2023 1:28 am
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();

}
}

Re: Attn: llSleep Haters - advise please

Posted: Sun Jan 22, 2023 2:11 am
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

Re: Attn: llSleep Haters - advise please

Posted: Sun Jan 22, 2023 2:30 am
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

Re: Trouble llSleeping - advise please

Posted: Sun Jan 22, 2023 11:22 am
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;
    }
}

Re: Trouble llSleeping - advise please

Posted: Sun Jan 22, 2023 5:28 pm
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.

Re: Trouble llSleeping - advise please

Posted: Sun Jan 22, 2023 11:48 pm
by Shandon Loring
Thank you all for insight and advice!