Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

timer event is triggered too soon.....

Tomfox Wiranata
Registered User
Join date: 20 Dec 2006
Posts: 80
02-08-2007 05:49
Hi everybody...

...again there is a weird error in my script. After a resident payed my machine a llSetTimerEvent is initialised for 180 seconds. But soon after the resident pays the timer event is triggered and the resident gets logged off. This is weird. This error occurs totaly NOT periodic. Some time he does, some time he does not.

I just initialized the llSetTimerEvent() ONCE. With 180s.

Funnily enough it worked when a resident had to touch the terminal, after he payed. In the current version no touch necessary. After he payed he processes.

CODE



touched(key toucher)
{
if (currentUser == toucher || currentUser == NULL_KEY)
{
//llSetTimerEvent(0);
llInstantMessage(currentUser,"You are the current user of this terminal");

name = llDetectedName(0);
integer ch = ChannelFromName(name);

llListen(ch,"",currentUser,"");
}

else
{
llInstantMessage(currentUser,"This system is already in use. ");
}

}





default
{
state_entry()
{
llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
state idle;
}
}



state idle
{
state_entry()
{
resetParameters();
llSetText("",<1,0,0>,1);
llSetPayPrice(PAY_HIDE,[15,30,45,60]);
}


money(key giver, integer amount)
{
name = llDetectedName(0);
integer ch = ChannelFromName(name);

currentUser=giver;
refund = amount;
howlong = ((amount / 15) * 7);
draws = amount/15;

state payed;
}

}





state payed
{

state_entry()
{
integer ch = ChannelFromName(name);
llListen(ch,"",currentUser,"");
llSetTimerEvent(180);
touched(currentUser);

}

listen()
{
...
}

timer()
{

llInstantMessage(currentUser,"Time is up. You were logged off");
llGiveMoney(currentUser, refund);
currentUser = NULL_KEY;

state idle;
}



Thx so much :)
Woopsy Dazy
Registered User
Join date: 12 Nov 2006
Posts: 173
02-08-2007 07:35
You must set the timer to 0 after it has triggered. llSetTimerEvent(0.0);
Woopsy Dazy
Registered User
Join date: 12 Nov 2006
Posts: 173
02-08-2007 07:37
CODE


timer()
{

llSetTimerEvent(0.0);
llInstantMessage(currentUser,"Time is up. You were logged off");
llGiveMoney(currentUser, refund);
currentUser = NULL_KEY;

state idle;
}

Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
02-08-2007 10:21
To clarify what Woopsy said, for some reason, LSL keeps llSetTimerEvent() settings even through a state change (unlike listens). So what's happening is that sometimes, a previous timer event has already queued up, or queues up soon after you enter the "payed" state. Woopsy's technique will work, but one thing I do as a general matter of coding practice is to always put this in any state in which I call llSetTimerEvent():

CODE

state_exit() {
llSetTimerEvent(0);
}
Tomfox Wiranata
Registered User
Join date: 20 Dec 2006
Posts: 80
02-08-2007 10:54
thx you guys..... ;)
Tomfox Wiranata
Registered User
Join date: 20 Dec 2006
Posts: 80
02-09-2007 08:44
well i did add the llSetTimerEvent(0), but it still does not work .....


some other ideas?
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
02-09-2007 10:25
Set the timer trigger to 0 in a state_exit() event in default AND in payed. That seems to catch all the odd timer-triggers - on-state-change wierdness.
_____________________