Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Door script but no timer

Jackson Racer
Mhm I gotta SL Blog
Join date: 19 Dec 2006
Posts: 130
02-09-2008 06:15
I have this door script but im not sure where i need to add the timer event so the door closes on its own. I'm sure this is super simple but i cant wrap my head around it.


[/php]
// If door is locked, the name of the avatar who locked it.
// If door is not locked, the empty string ("";).
string gLockedBy = "";

// This number must match the channel number of the lock
// and unlock objects you want to use. If multiple doors
// have the same channel, then a single lock can lock all of
// them at once.
integer gLockChannel = 243;

default
{
state_entry()
{
llSay(0, "Door 1.0";);
llListen(gLockChannel, "", NULL_KEY, "";);
state closed;
}
}

state closed
{
listen(integer channel, string name, key id, string message)
{
if (channel == gLockChannel)
{
if (message == "";)
{
gLockedBy = "";
//llTriggerSound("door unlock", 10.0);
llSay(0, "unlocked";);
}
else
{
gLockedBy = message;
//llTriggerSound("door lock", 10.0);
llSay(0, "locked";);
}
}
}

touch_start(integer total_number)
{
string name = llDetectedName(0);
if (name == gLockedBy || gLockedBy == "";)
{
llTriggerSound("Door open", 10.0);

rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,PI/4>;);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
state open;
}
else
{
llTriggerSound("Door knock", 10.0);
}
}
}

state open
{
touch_start(integer num)
{
llTriggerSound("Door close", 10.0);

rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,-PI/4>;);
rot = delta * rot;
llSetRot(rot);

llSleep(0.25);
rot = delta * rot;
llSetRot(rot);

state closed;
}
}
[/php]
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
02-09-2008 06:49
First you need declare the llSetTimerEvent in a "0" value in this case in your state_entry of your "state open" then the timer(llSetTimer Event(sec to 0 value)) {} and inside of the touch_start{llSetTimerEvent(sec to run after the door is closed)}

example:


CODE

float DlockTimeDoor=0.0;//<---0 value for our timer


default
{
state_entry()
{
//some code
state closed;
}
}

state closed
{
{
//your listen code
}

touch_start(integer total_number)
{
//touch statement
{
state open;
}
else
{
//else code
}
}
}
state open
{
state_entry()
{
llSetTimerEvent(DlockTimeDoor);//<--set your timer event
}

touch_start(integer num)
{
//touch event rot calculation
llSetTimerEvent(0);//<---- reset to 0 value to cancel the timer
state closed;//<--back to closed state
}

timer()//<------execute timer event
{
llSetTimerEvent(0);//<--like in the touch event reset the timer to 0 so the timer is not executes any more
state closed;
}
}

[\CODE]

CODE


// If door is locked, the name of the avatar who locked it.
// If door is not locked, the empty string ("").
string gLockedBy = "";

// This number must match the channel number of the lock
// and unlock objects you want to use. If multiple doors
// have the same channel, then a single lock can lock all of
// them at once.
integer gLockChannel = 243;
float DlockTimeDoor=10.0;//<-------float value for the timer door

default
{
state_entry()
{
llSay(0, "Door 1.0");
llListen(gLockChannel, "", NULL_KEY, "");
state closed;
llSetTimerEvent(0.0);
}
}


state closed
{
listen(integer channel, string name, key id, string message)
{
if (channel == gLockChannel)
{
if (message == "")
{
gLockedBy = "";
//llTriggerSound("door unlock", 10.0);
llSay(0, "unlocked");
}
else
{
gLockedBy = message;
//llTriggerSound("door lock", 10.0);
llSay(0, "locked");
}
}
}

touch_start(integer total_number)
{
string name = llDetectedName(0);
if (name == gLockedBy || gLockedBy == "")
{
llTriggerSound("Door open", 10.0);

rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
state open;
}
else
{
llTriggerSound("Door knock", 10.0);
}
}
}

state open
{
state_entry()
{
llSetTimerEvent(DlockTimeDoor);//second past since the state entry was executed and timer run to the door get closed
}


touch_start(integer num)
{
llTriggerSound("Door close", 10.0);

rotation rot = llGetRot();
rotation delta = llEuler2Rot(<0,0,-PI/4>);
rot = delta * rot;
llSetRot(rot);
llSleep(0.25);
rot = delta * rot;
llSetRot(rot);
llSetTimerEvent(0);//<---- reset to 0 value to cancel the timer
state closed;//<--back to the closed state
}



timer()//<------execute timer event
{
llSetTimerEvent(0);//<--like in the touch event reset the timer to 0 so the timer is not executes any more
llTriggerSound("Door close", 10.0);
state closed;//<--back to the closed state
}
}
[\CODE]
Jackson Racer
Mhm I gotta SL Blog
Join date: 19 Dec 2006
Posts: 130
02-11-2008 10:51
Ha ha!! Thank you! Worked like a charm!
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
02-11-2008 15:17
your wellcome Jackson, any cusestion just ask in the forum all us would be happy to help you ;)