Brand new to LSL. I hacked apart a door script to make retractable doors. They work fine, open/close, but want them to know which state they're in, and not over-open or -close. I thought I'd figured it out, but they keep going, with successive presses from the remote.
CODE
key owner;
// Will be used to retrieve owner's key.
integer iSteps = 15;
// How many steps the door will open in, used to provide the
// illusion of sliding. Fewer steps means it opens faster,
// but more steps will make it "slide" smoother.
vector vOffset = <0.15, 0.0, 0.0>;
// Indicates how far the door will move with each step.
// Multiply by iSteps to calculate the total distance the
// door will move.
integer bMove = FALSE;
integer abOpen = TRUE;
integer abClose = FALSE;
//*********************************************
// open() close() -- the meat and taters of the code,
// makes the door actually move.
//*********************************************
open()
{
bMove = TRUE;
integer i;
vector basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
bMove = FALSE;
llOwnerSay("open script");
}
close()
{
bMove = TRUE;
integer i;
vOffset *= -1;
vector basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
bMove = FALSE;
llOwnerSay("close script");
vOffset *= -1;
}
default
{
//************************************************** *
// state_entry() -- set up our global variables and
// initialize the listen events.
//************************************************** *
state_entry()
{
owner = llGetOwner();
llListen(101,"",NULL_KEY,"");
}
//************************************************** *
// listen() -- listen for owner or those allowed to
// open and close the doors.
// Also checks if door is already open or closed
// Simply add more Key2Name functions
// to add users.
//************************************************** *
listen(integer chan, string name, key id, string msg)
{
if (name == "roof_Open" || id == owner || llKey2Name(id) == "John Doe" && msg == "open") {
if ( abOpen = TRUE ) {
llOwnerSay("before open");
abOpen = FALSE;
abClose = TRUE;
open();
llOwnerSay("after open");
}
}
if (name == "roof_Close" || id == owner || llKey2Name(id) == "John Doe" && msg == "close") {
if ( abClose = TRUE ) {
llOwnerSay("before close");
abOpen = TRUE;
abClose = FALSE;
close();
llOwnerSay("after close");
}
}
}
}
I left in debug points, and it doesn't seem to be messing up anyplace noticeable. Thanks for the help.