Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

I need to time an event, but listen while the timer runs...

Lief Rush
Registered User
Join date: 15 Dec 2006
Posts: 18
12-26-2007 01:29
Can I do that in LSL? It appears that my Listen will die while I use settimerevent commands? Am I seeing that right? In other words, I want to keep listening for commands, but every so often also check to see if the script should stop listening for commands, using a timed checkin with a httprequest. I hope I make sense, thanks in advance for any light any can shed.
Talon Brown
Slacker Punk
Join date: 17 May 2006
Posts: 352
12-26-2007 01:42
Sure, you can have a listener open while running a timer event. Events don't prevent each other from occuring, are you sure you're not mistaking a timer event for llSleep? The latter will stop your script from doing anything for the duration of its sleep.
Lief Rush
Registered User
Join date: 15 Dec 2006
Posts: 18
12-26-2007 01:53
From: Talon Brown
Sure, you can have a listener open while running a timer event. Events don't prevent each other from occuring, are you sure you're not mistaking a timer event for llSleep? The latter will stop your script from doing anything for the duration of its sleep.


I think you are right... To much reading in a short period.. I just need to figure out a good strategy to build a timer then, whether settimerevent or a Do/While style. Will search the forums!! Thanks for the speedy reply.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-26-2007 02:31
From: Lief Rush
I think you are right... To much reading in a short period.. I just need to figure out a good strategy to build a timer then, whether settimerevent or a Do/While style. Will search the forums!! Thanks for the speedy reply.

you don't want a do loop timer.... at least not in most cases.

while your loop is running any incoming listens will trigger, but be queued, until the loop is exited and the next queued event can run. in most scenarios that will mean your loop prevents incoming changes. this behavior CAN be useful if you are completing tasks that need to finish before the next listen is proccessed, but in the case of needing to get input in between loops it's disasterous as they are all effectively put on hold while the loop is running.

instead the usual method would be to put your loop code inside the timer event (or a sub function called from the timer) and call it on a regular basis... add you conditions for the loop inside the timer using and if statment, and when it hits it's break point call llSetTimerEvent 0.0 );

it's also a good idea not to set your timer faster than the code in the loop will complete, or you may end up with a queued timer event before your code completes, which will run your loop code an extra time above what you might normally want.
_____________________
|
| . "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...
| -
Lief Rush
Registered User
Join date: 15 Dec 2006
Posts: 18
12-26-2007 10:13
From: Void Singer
you don't want a do loop timer.... at least not in most cases.

while your loop is running any incoming listens will trigger, but be queued, until the loop is exited and the next queued event can run. in most scenarios that will mean your loop prevents incoming changes. this behavior CAN be useful if you are completing tasks that need to finish before the next listen is proccessed, but in the case of needing to get input in between loops it's disasterous as they are all effectively put on hold while the loop is running.

instead the usual method would be to put your loop code inside the timer event (or a sub function called from the timer) and call it on a regular basis... add you conditions for the loop inside the timer using and if statment, and when it hits it's break point call llSetTimerEvent 0.0 );

it's also a good idea not to set your timer faster than the code in the loop will complete, or you may end up with a queued timer event before your code completes, which will run your loop code an extra time above what you might normally want.



Thanks Void. thats exactly what I am trying to avoid, so the Do/While Loop is not the answer for me.. I will find some settimerevent code then in the forums and play with it!! Should be simple as I just want it to ask every once in a while if it should keep listening, or go to deep sleep. Thanks to both of you!!
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-27-2007 04:29
From: Lief Rush
Thanks Void. thats exactly what I am trying to avoid, so the Do/While Loop is not the answer for me.. I will find some settimerevent code then in the forums and play with it!! Should be simple as I just want it to ask every once in a while if it should keep listening, or go to deep sleep. Thanks to both of you!!

assuming the timer/loop is just running to detect whether or not it should keep listening you could set an automatic timeout that resets every time it's used... I use this for almost all my dialogs so that the listens don't stay open if they get ignored...

basic code
CODE

default{
touch_start( integer vIntTouched ){
do{
--vIntTouched;
//-- call dialog for each person that touched
//-- open a listen for each person that touched
llSetTimerEvent( 45.0 ); //-- wait 45 seconds
}while (vIntTouched);
}

//-- insert listen code

//-- this only triggers 45 second after the LAST last listen is opened
//-- if another listen is triggered before then it waits 45 seconds from that one
timer(){
llsetTimerEvent( 0.0 );
state sListenKiller;
}
}

state sListenKiller{
state_entry(){
state default;
}
}


I use this same method to turn off a chat calculator after five minutes if it isn't being used
_____________________
|
| . "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...
| -