llSetTimerEvent queuing events
Mars Tamale
Wiki should be updated to warn scripters that timer events may arrive during executing/processing something else that at some point changes the timer. This causes the Timer event to be raised immediately on exit.
Recommendation to scripters is that when changing timer events that llSetTimerEvent(0.0); is issued before the new llSetTimerEvent is called. This clears any events that have been raised whilst the current function/event is executing.
integer lastTime;
default
{
state_entry()
{
lastTime = llGetUnixTime();
llSetTimerEvent(5);
llOwnerSay("Timer set to 5 secs");
}
touch_start(integer total_number)
{
integer n = llGetUnixTime();
// llSetTimerEvent(0); // clears timer events that may arrive during processing this event
llOwnerSay((string)n+" Sleeping");
do
{}
while (llGetUnixTime() < (n+10));
//llSetTimerEvent(0); // clears timer events first then ...
llSetTimerEvent(30);
llOwnerSay((string)llGetUnixTime()+" Awake timer set to 30 secs");
}
timer()
{
integer n = llGetUnixTime();
llOwnerSay((string)n+" Timer event "+(string)(n-lastTime));
lastTime = n;
}
}
Generates:
[03:03:40] Object: Timer set to 5 secs
[03:03:45] Object: 1734865426 Timer event 5
[03:03:50] Object: 1734865431 Timer event 5
[03:03:51] Object: 1734865432 Sleeping
[03:04:00] Object: 1734865442 Awake timer set to 30 secs
[03:04:00] Object: 1734865442 Timer event 11 ----- event immediately despite new timer
[03:04:30] Object: 1734865471 Timer event 29
Removing either commented out llSetTimerEvent(0) corrects the issue.
Its not a bug just one of those annoying things that can frustrate you for ages before you realise what's going on. :-)
Log In
Peter Stindberg
``
If you log into the wiki and see you do not have edit privileges, you'll need to request them by emailing letmein@lindenlab.com. Please send them a polite email asking for editing permission.
``Apply for editing access and amend it yourself.