Jump to content

Yet another multiple timer


KT Kingsley
 Share

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

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

Recommended Posts

There's been a question in a scripting thread about using multiple times in a single script, so I'll offer up my take on the subject here.

I've been using this without problem for quite a while now but, as with all scripts, I expect people will find their own problems when they try to use it.

list timer_events;

SetTimerEvent (string label, float interval)
{
    integer index = llListFindList (timer_events, [label]);
    if (interval <= 0.0)
    {
        if (~index)
        {
            timer_events = llDeleteSubList (timer_events, ~-index, -~index);
            if (timer_events == []) llSetTimerEvent (0.0);
        }
    }
    else 
    {
        list this_event = [llGetTime () + interval, label, interval];
        if (~index) timer_events = llListReplaceList (timer_events, this_event, ~-index, -~index);
        else timer_events = this_event + timer_events;
        timer_events = llListSort (timer_events, 3, TRUE);
    }
    if (timer_events)
    {
        interval = llList2Float (timer_events, 0) - llGetTime ();
        if (interval <= 0.0) interval = 0.01;
        llSetTimerEvent (interval);
    }
}

StopAllTimerEvents ()
{
    llSetTimerEvent (0.0);
    timer_events = [];
}

string GetTimerEventLabel ()
{
    string label = llList2String (timer_events, 1);
    float interval = llList2Float (timer_events, 2);
    timer_events = llListSort (llListReplaceList (timer_events, [llGetTime () + interval, label, interval], 0, 2), 3, TRUE);
    interval = llList2Float (timer_events, 0) - llGetTime ();
    if (interval <= 0.0) interval = 0.01;
    llSetTimerEvent (interval);
    return label;
}

To start and stop a timer event use the function SetTimerEvent with either a non-zero or zero interval. You must also supply a string label to identify the specific timer event.

In the timer event itself use the function GetTimerEventLabel to get the indentifying label for the specific timer event, and use this to select the appropriate course of action. This function also sets the timer up for the next event.

There's also the StopAllTimerEvents function, because sometimes you want to do that.

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 3 weeks later...
You are about to reply to a thread that has been inactive for 1484 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...