Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Timer Misfiring?

Weasel Wingtips
Registered User
Join date: 17 Sep 2007
Posts: 7
02-26-2008 07:51
I have a problem, I think my timer is misfiring and I have no idea why.

From: someone

integer error_timeout = 45;

state useful_state {
state_entry() {
llOwnerSay("A";);
sendmsg("send_data","";);
llSetTimerEvent(error_timeout);
llResetTime();
}

timer() {
llOwnerSay("B";);
state default;
}

link_message(integer sender_num, integer num, string msg, key msg2) {
if (msg=="response" && "1" == msg2) {
llOwnerSay("C";);
state moveon;
}
}
}


There's the suspect state I have in my code; "sendmsg" is a function I made that just reformats linkmsg. What I have is this script that sends a message to another script, and receives a response. I have some error catching (it'll restart itself if no response received for example).

What is supposed to happen:

From: someone

Object: A
Object sends linkmsg
Object initializes the timer for 45 seconds
Object receives message in response
Object: C
Object moves to moveon state.


What actually happens:

From: someone

Object: A
Object sends linkmsg
Object initializes the timer for 45 seconds
Obecjt: B
Object moves to default state
Object reports a response was received but doesn't know what to do with it (as it's no longer in the correct state to process it)
-- other script timesout and retries --
Object: A
Object sends linkmsg
Object initializes the timer for 45 seconds
Object receives message in response
Object: C
object moves to moveon state.


It's very strange, it always fails the first time around.. but upon second attempt (it automatically keeps retrying until it works) it suddenly works again. I inserted the OwnerSay messages for debugging; that's how I verified that the timer is misfiring within the span of about a second of being called. I don't have the timer misconfigured as far as I can tell; I don't redefine error_timeout anywhere either.

Elsewhere in the script I do make use of the timer, and the error_timeout variable, but this shouldn't conflict when changing states, right?

The error_timeout variable is also reused in several other scripts in the same object.. that shouldn't matter though, right? :)

Please help!
Weasel Wingtips
Registered User
Join date: 17 Sep 2007
Posts: 7
02-26-2008 07:56
Of course I scratch my head over this for weeks and then I realize...

wait a minute...

From: Wiki

The timer survives state changes


OK.. so I'm thinking a solution might be to llSetTimer(0); upon exit of all my other states?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
02-26-2008 09:29
likely your timer event is sometimes(always?) being queued before the state entry declaration for set timer goes into effect...

I'm not sure how the timer behaves in a state with no timer event, it could be that it's being queued there, but never processing, but as soon as it reaches the new state, it's still queued, so isn't postphoned by the set timer call in state_entry.

in any case, clearing the timer on state change should fix the problem, the upside as you may have discovered, is that you can maintain some regularly firing code, even if you change states, by adding it (or better a custom function) to the timer in each state...
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -