Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Waiting for Listens....

Dominus Skye
Bug Magnet
Join date: 31 Oct 2004
Posts: 54
02-09-2005 19:09
I have the need to wait for a listen from within a FOR loop, problem I am experiencing is it appears that whilst the script is looping, it won't 'hear' a listen .... and neither will it if I put the script to sleep, so what is the best way to accomplish this?

Assume the listen has been setup in the state_entry function, and that there is a valid listen function as well, so the format I'd like to achieve is then in pseudo-code....

integer x;
for (x=0;x<whatever;x++)
{
do this....
and this...
and this ....
now wait for response from object or user, set within the listen handler, then loop again only when it has been received
}
Danny DeGroot
Sub-legendary
Join date: 7 Jul 2004
Posts: 191
02-09-2005 19:29
Try making your "x" and "whatever" global, then run through the loop once right inside your listen handler:


integer x = 0;
integer whatever = 40;


...

listen( integer channel, string name, key id, string msg )
{

// do stuff
// more stuff
x += 1;
if ( x == whatever ) {
// Shut down this listener, or change states, or something
//
}
}

== danny d.


PS Sorry, just realized you apparently want the thing to run once before the first listen. I think you'll need to put the code in a global function, and call that function once from your state_entry and repeatedly from your listen.

But some library calls only work inside state handlers, and can't be invoked from global functions. If you get an error on compiling the function, you'll need to just drop copies of the "Do stuff" logic into both your listener and your state_entry().
Dominus Skye
Bug Magnet
Join date: 31 Oct 2004
Posts: 54
02-09-2005 20:26
Thanks Danny, you're perfectly right of course.

Sighs, I feel particularly thick today.... :(
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
02-09-2005 20:27
Any time you are executing code, event handlers (like listen) will not trigger. For loops are executing code, llSleep() is executing code. Events will queue up until any active code is done. Put another way, until the script is doing nothing, events will not trigger.

I could not tell from your description, but you may want to look at states (which I think of as "different sets of event handlers";). That is, your "sit tight until another user action" is probably best handled by a state switch. If you want to post more code, it might help.