Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Losing pay events during Sleep()...

Adman Drake
Registered User
Join date: 9 Feb 2006
Posts: 96
03-16-2006 10:16
I'm at work right now, but wondered if someone could confirm this...

I had a script that did a llSleep(10). I found that if someone paid the object during this time, the object accepted the payment, but the money event never fired.

Actually, it wasn't quite as simple as that... The Sleep() call was in one state (with a money block), and soon after the sleep, the script changed states back to default. So it was actually something like this:

CODE

state default
{
touch()
{
next_state;
}
}

state next_state
{
state_entry()
{
say("I'm in next_state");
sleep(10)
say("I just woke up!");
default;
}

money(id, amount)
{
say("I got paid!")
}
}


If I pay the object during the sleep in "next_state", when should I expect the money event to fire?

a) during the sleep?
b) IMMEDIATELY after the sleep?
c) at the end of state_entry?

If the answer is c, and the last line in state_entry of next_state actually switches state, could it be that the money event is never called?

Thanks for any assistance you can provide.

Adman
Introvert Petunia
over 2 billion posts
Join date: 11 Sep 2004
Posts: 2,065
03-16-2006 10:23
As noted in the Events documentation switching states will clear the event queue, and llSleep is a "blocking" call which means events will not get serviced until it returns.

Given the pseudo-code you posted, it is possible that the money event is getting discarded from the queue at your "default;" statement.

ADDED: You should only expect events to fire when there is no code block currently executing. For example, the money event will not fire while state_entry() is executing and therefore the answer is (D) none of the above you should expect money to never fire given the example structure you showed.
Kalleb Underthorn
Registered User
Join date: 30 Jul 2003
Posts: 40
03-16-2006 10:23
I would assume this would NOT work... simply because scripts are syncronous. Once it is done sleeping, it will continue executing that code (before triggering other events). Once it hits 'default', the event handlers will change, and then the events will be handled. I'm also fairly certain that the event buffer is flushed when you change states... but I can't really remeber on that one.
Adman Drake
Registered User
Join date: 9 Feb 2006
Posts: 96
03-16-2006 10:36
From: Introvert Petunia

ADDED: You should only expect events to fire when there is no code block currently executing. For example, the money event will not fire while state_entry() is executing and therefore the answer is (D) none of the above you should expect money to never fire given the example structure you showed.


Great... this sounds exactly like what's happening.

What I did to fix this, by the way, was change the sleep into a SetTimerEvent(10). Then I did the rest of my code in the timer block. That freed up the script to handle money events. I guess if someone paid during the executing time of the timer block (or whatever block ends in switching states), that could be a problem, but that should be rare.

Thanks so much!
Adman