Jump to content

Script with timer delay


Tattooshop
 Share

You are about to reply to a thread that has been inactive for 1466 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi! Often there is a problem when a script with a timer does not work immediately. you have to wait a few seconds  (10 seconds as in this script). how to make it work right away? (I tried to add llSetTimerEvent(0); at the top of timer event but did not work..

integer toggle;
vector lColor = < 1.0, 1.0, 1.0 > ;

default
{
    touch_start(integer total_number)
    {
        if (llDetectedKey(0) == llGetOwner())
        {
            if (toggle)
            {
                toggle = FALSE;
                llSetTimerEvent(0.0);
                llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, ALL_SIDES, FALSE, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR,
                    0.0, 0.0, 1]);
            }
            else
            {
                toggle = TRUE;
                llSetTimerEvent(10);
            }
        }
    }
    
    timer()
    {
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, 0, .1, PRIM_FULLBRIGHT, 0, 1, PRIM_POINT_LIGHT, TRUE, lColor, 1.0, 3.0, 0.2]);
        llSleep(1);
        
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, 1, .1, PRIM_FULLBRIGHT, 1, 1]);
        llSleep(5);
        
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, ALL_SIDES, FALSE, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0.0, 0.0,
            1]);
    }
}

 

Link to comment
Share on other sites

49 minutes ago, Tattooshop said:

Often there is a problem when a script with a timer does not work immediately. you have to wait a few seconds

That is how the timer is designed. When you call llSetTimerEvent() with a positive number, the timer event will trigger after the specified interval has elapsed. It's like a countdown. Specifying a zero will cancel the timer's internal countdown. See the function's wiki page for details.

If you want your actions to happen immediately, before the timer goes through its countdown, then you must explicitly perform them outside the timer event as well. You can do that several ways. The most straightforward way would be to literally copy the code you have in the timer event and place it in the appropriate spot in your touch_start event (like just after you start the timer countdown with llSetTimerEvent(10.0))

Another way of doing that is to move your action to a user defined function and then call that in the touch_start event and then in the timer.

customFunction()
{
  //stuff to do
}

default
{
    touch_start(integer total_number)
    {  
      llSetTimerEvent(10.0);
      customFunction();		//do the thing right away
    }
    
    timer()
    {
      customFunction();		//do the thing every 10 seconds
    }
}
Edited by Fenix Eldritch
  • Thanks 1
Link to comment
Share on other sites

2 hours ago, Rolig Loon said:

Change that statement in touch_start to llSetTimerEvent(0.1);  and then add llSetTimerEvent(10.0); to your timer event.

 

2 hours ago, Fenix Eldritch said:

Another way of doing that is to move your action to a user defined function and then call that in the touch_start event and then in the timer.


 

 

Excellent! Thanks very much both of you! I now have two working versions of the script! 🤎😎👍

Could you please give a hint how to make it also turn off right away? :D

 

Link to comment
Share on other sites

// Rolig's version

integer toggle;
vector lColor = < 1.0, 1.0, 1.0 > ;

default
{
    touch_start(integer total_number)
    {
        if (llDetectedKey(0) == llGetOwner())
        {
            if (toggle)
            {
                toggle = FALSE;
                llSetTimerEvent(0.0);
                llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, ALL_SIDES, FALSE, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR
                    , 0.0, 0.0, 1]);
            }
            else
            {
                toggle = TRUE;
                llSetTimerEvent(0.1);
            }
        }
    }
    
    timer()
    {
        llSetTimerEvent(10.0);
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, 0, .1, PRIM_FULLBRIGHT, 0, 1, PRIM_POINT_LIGHT, TRUE, lColor, 1.0, 3.0, 0.2]);
        llSleep(1);
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, 1, .1, PRIM_FULLBRIGHT, 1, 1]);
        llSleep(5);
        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, ALL_SIDES, FALSE, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0.0, 0.0
            , 1]);
    }
}
// Fenix's Version

integer toggle;
vector lColor = < 1.0, 1.0, 1.0 > ;

lightFunction()
{
    llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, 0, .1, PRIM_FULLBRIGHT, 0, 1, PRIM_POINT_LIGHT, TRUE, lColor, 1.0, 3.0, 0.2]);
    llSleep(1);
    llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, 1, .1, PRIM_FULLBRIGHT, 1, 1]);
    llSleep(5);
    llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, ALL_SIDES, FALSE, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0.0, 0.0, 1]);
}

default
{
    touch_start(integer total_number)
    {
        if (llDetectedKey(0) == llGetOwner())
        {
            if (toggle)
            {
                toggle = FALSE;
                llSetTimerEvent(0.0);
                llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, ALL_SIDES, FALSE, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0.0, 0.0, 1]);
            }
            else
            {
                toggle = TRUE;
                llSetTimerEvent(10);
                lightFunction();
            }
        }
    }
    
    timer()
    {
        lightFunction();
    }
}

May come in handy to someone :D

 

Link to comment
Share on other sites

2 minutes ago, Tattooshop said:

Could you please give a hint how to make it also turn off right away?

It should already.  Your touch_start event looks for 

if (toggle)
            {
                toggle = FALSE;
                llSetTimerEvent(0.0);
                llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLOW, ALL_SIDES, FALSE, PRIM_FULLBRIGHT, ALL_SIDES, FALSE, PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR,
                    0.0, 0.0, 1]);
            }

which contains the SLPPF commend to turn off the glow, fullbright, and point light, and th  llSetTimerEvent(0.0) to turn off the timer and keep it from firing again.

  • Thanks 1
Link to comment
Share on other sites

The usage of sleep event within the timer is by no means optimal, I would even  say counter productive.

Best way would be to to call the timer and measure elapsed millisecond (or seconds) within the timer and proceed with the needed tasks based on the elapsed time.

Further 100 ms timer for changing lights, full bright is simply an overkill IMHO, especial as llSleep uses whole seconds.

 

Link to comment
Share on other sites

1 hour ago, Rachel1206 said:

The usage of sleep event within the timer is by no means optimal, I would even  say counter productive.

Best way would be to to call the timer and measure elapsed millisecond (or seconds) within the timer and proceed with the needed tasks based on the elapsed time.

Further 100 ms timer for changing lights, full bright is simply an overkill IMHO, especial as llSleep uses whole seconds.

 

Thats very interesting! :D

Do I understand correctly, it will be something like:

float time = llSetTimerEvent(10)/10;

if time == 0 do stuff

if time == 1 do stuff

if time == 5 do stuff

if time == 10 do stuff...?

Edited by Tattooshop
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1466 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...