Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

how to ensure timer() event isn't called initially when moving between states??

Greg Hauptmann
Registered User
Join date: 30 Oct 2005
Posts: 283
02-14-2006 18:24
Hi,

I'm doing a timer reset in different states of my script, following the appraoch:

CODE
	
state_entry() {
<<other stuff>>
llResetTime();
llSetTimerEvent(GAME_TIMEOUT_TIME);
...


It would seem that when I jump back to the first state the timer() event is being called, whereas I don't want it to, and I wouldn't have expected it too. I guess if the timer is global to the script a timer event could have occured between the point I go back to the first state adn when the state gets to the line with "llResetTime" in it. Could this be what is happening?

Q - Is there a way to ensure that a timer() event isn't called when I move into another state between the state_entry() code can hit the llResetTime() and llSetTimeEvent lines are hit?

Thanks
Greg Hauptmann
Registered User
Join date: 30 Oct 2005
Posts: 283
02-14-2006 18:33
PS. Just realised too I am not issuing a llSetTimerEvent(0) when I leave a state - could this be the missing code I need to correct things?
Kermitt Quirk
Registered User
Join date: 4 Sep 2004
Posts: 267
02-14-2006 18:38
I agree that it's a bit odd timers seem to remain between states like that. I've come across this before and have got into a habit of doing exactly what you suggested. If there's any chance a timer might still be running and I'm going to be changing states, I always put a llSetTimerEvent(0.0) in the state_exit just to be sure it's shut off properly.
Greg Hauptmann
Registered User
Join date: 30 Oct 2005
Posts: 283
02-14-2006 18:41
thanks Kermitt - I'll try this out
Fenrir Reitveld
Crazy? Don't mind if I do
Join date: 20 Apr 2005
Posts: 459
02-14-2006 19:02
Yes, I always clear out the timer, upon state_exit(), or upon state_entry(). The wiki states that all pending events are cleared, but it seems the timer will slip past. I suspect that llSetTimerEvent() works by placing a "wait until X time to fire timer event" flag upon the state, instead of actually placing an event upon the queue, so when you switch back to a state that had a timer previously set, this gets triggered. ("Oh, I had a timer event and it was scheduled -12 seconds ago...";)

If you do llSetTimerEvent (0), this state flag is cleared.

(Probably could test this by setting a timer event for 20 seconds, sleep for 10.0 seconds, then switch states. Sleep for another X seconds, then switch to prior state. If the timer event fires and X is greater than combined initial timer interval, that is probably what is going on.)
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
02-15-2006 01:15
Has anyone tried calling llSetTimerEvent() from a state without a timer and then switching to a state that does have it? I'm curious if the timer event would be called (not in SL to do the test myself atm).
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
02-15-2006 09:28
It's been my experience, too, that llSetTimerEvent() seems not to be cleared on state exit... so I always put it in manually in my state_exit().

Also, a note: llResetTime() is completely different from and unrelated to llSetTimerEvent() and the timer() event.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
02-15-2006 13:27
To answer Strife's question, yes it does.

This script:
CODE

default
{
state_entry()
{
llSetTimerEvent(5.0);
state test;
}
}

state test
{
timer()
{
llOwnerSay("Timer fired");
}
}


Gave this output:
CODE

Object: Timer fired
Object: Timer fired
Object: Timer fired
Object: Timer fired
Object: Timer fired
Object: Timer fired
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
02-15-2006 13:35
Well, the Wiki says that the timer itself will be retained through state changes. What is more interesting is whether queued-up timer events will be retained as well. I think calling llSetTimerEvent(0) stops further timer events, it doesn't remove the ones already in the queue. So I'd be curious about what the following two scripts do:

CODE

default
{
state_entry()
{
llSetTimerEvent(5.0);
llSleep(10.0);
llSetTimerEvent(0.0);
}

timer()
{
llSay(0, "timer fired 1");
}
}


CODE

default
{
state_entry()
{
llSetTimerEvent(5.0);
llSleep(10.0);
llSetTimerEvent(0.0);
state two;
}
}

state two
{
timer()
{
llSay(0, "timer fired 2");
}
}


Though I wonder if llSleep means timer events don't get posted. I don't think so.
Greg Hauptmann
Registered User
Join date: 30 Oct 2005
Posts: 283
02-15-2006 15:02
From: Lex Neva
llResetTime() is completely different from and unrelated to llSetTimerEvent() and the timer() event.
Oh..I'm offline..but I'd been assuming that this resets the script timer value back to 0. That is, I was imagining it was a stopwatch that starts counting up from 0, and you can specify when the timer() event can trigger, but also you can set it back to 0 to start it counting again.

Am I offtrack here?
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
02-15-2006 18:49
llResetTime et al time functions do not effect timer events. Sorry for any confusion that suggested otherwise.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Greg Hauptmann
Registered User
Join date: 30 Oct 2005
Posts: 283
02-15-2006 20:42
So does llSetTimerEvent(x) effectively perform two things then, these being:
(a) reset the period between timer() events and
(b) "reset the timer() clock", i.e. so that the next timer() event won't been until a full X seconds

Also, getting back to my original question if I may, does what I describe sound like a fundamental LSL/SL constraint? That is, there are no other ways to implement a centralised status/workflow system which would work significantly quicker?

Thanks again