Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to sleep part of a script?

Dina Vanalten
Registered User
Join date: 24 Dec 2006
Posts: 268
06-07-2007 08:55
Hi.

I want to have one of my script states sleep while another runs. I looked at llSleep but the description seems to indicate that the whole script goes to sleep.

This is what I'm trying to do:

-----------------------------------------

state_entry()
{
reading_options_card = TRUE;
llGetNumberOfNotecardLines(optionscardName);

do
{
llSleep(2);
} while (reading_options_card);

... more code
}


dataserver(key queryid, string string_data)
{
... more code

reading_options_card = FALSE;
}

------------------------------------------------

The idea is to have the dataserver read the option card and get all the new values before the state_entry continues processing.

Any ideas would be appreciated.

Thanks - D
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
06-07-2007 09:35
States and events in the same script never run in parallel to one another. While your script is in any particular state and event within that state, it cannot do anything else but execute that code in that event in that state. As such, if you llSleep in it, it won't do anything else, until the Sleep is up and you exit the event or change states within that event.
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
06-07-2007 09:43
Just have the data_server event trigger the next action that is supposed to take place after it has finished executing.

dataserver(key queryid, string string_data)
{
if (string_data != EOF) {
// You read a good line
} else {
// End of Notecard reached
inti(); // function where more initialization code exists
}
}
Dina Vanalten
Registered User
Join date: 24 Dec 2006
Posts: 268
06-07-2007 10:36
From: Milambus Oh
Just have the data_server event trigger the next action that is supposed to take place after it has finished executing.

dataserver(key queryid, string string_data)
{
if (string_data != EOF) {
// You read a good line
} else {
// End of Notecard reached
inti(); // function where more initialization code exists
}
}


Uh. Thanks. That was obvious. Why didn't I think of it? They dont' call me a dumb blond for nothing. - D
Jake Trenchard
Registered User
Join date: 31 May 2007
Posts: 104
06-07-2007 11:53
Although chaining directly from the event you're waiting on is best in this case, in general you can do a non-blocking sleep by using a Timer event instead of llSleep. I expect it is best not to use timer event loops unless you have to, and only for as long as you really need them, as they are consuming continuous resources. Too many people (or objects) using timers too liberally and you are burning a lot of processing power all the time.