Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help needed with door script...

Colorado Moonites
Registered User
Join date: 11 Jul 2008
Posts: 1
07-20-2008 10:27
Hello all, I have a door script that does not close automatically. Is it possible to add a 10 second close timer to this? Any help is greatly appreciated! :)

CODE

// Iris Open Script by Cera Murakami - 7/21/2006
// Touch-sensitive iris opening door
// Toggles open and closed state for a hole in a torus as an iris door
// Put this script into a flattened torus.


// ----- Global Variables ------------------
integer g_OpenNow; // True (1) if iris is 'open' now

default
{
on_rez(integer param)
{
llResetScript();
}

state_entry()
{
if (g_OpenNow == TRUE) // Prim is in open state, so calculate new 'closed' size
{
state WaitToClose;
}
else // Prim is in a closed (or undefined state), so calculate new 'open' size
{
g_OpenNow = FALSE;
state WaitToOpen;
}
}
}

state WaitToClose // Iris is Open, and waiting to close
{
touch_start(integer total_number)
{
llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_TORUS, 0, <0.0, 1.0, 0.0>, 0.0, <0.0, 0.0, 0.0>, <1.0, 0.5, 0.0>, <0.0, 0.0, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 1.0, 0.0, 0.0]);
g_OpenNow = FALSE;
state WaitToOpen;
}
}

state WaitToOpen // Iris is closed, and waiting to open
{
touch_start(integer total_number)
{
llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_TORUS, 0, <0.0, 1.0, 0.0>, 0.0, <0.0, 0.0, 0.0>, <1.0, 0.05, 0.0>, <0.0, 0.0, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 1.0, 0.0, 0.0]);
g_OpenNow = TRUE;
state WaitToClose;
}
}
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-20-2008 12:14
A state_entry() handler in the WaitToClose state could llSetTimerEvent(10.0), and a timer() handler in that same state could do all the same stuff that's currently happening in touch_start() there. One might move "all the same stuff" to a function, so it could just be called from both places. [Edit: Such a function could do the llSetPrimitiveParams() call, but state changes from inside functions are... well, they're just not done. :o ]
_____________________
Archived for Your Protection
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
Another way of doing it.
07-20-2008 23:25
Could probably use some effeciency tweaking.
From: someone

// Iris Open Script by Cera Murakami - 7/21/2006
// Touch-sensitive iris opening door
// Toggles open and closed state for a hole in a torus as an iris door
// Put this script into a flattened torus.


// ----- Global Variables ------------------
integer g_OpenNow; // True (1) if iris is 'open' now
vector open = <1.0, 0.05, 0.0>;
vector close = <1.0, 0.5, 0.0>;

open_close(vector OC)
{
llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_TORUS, 0, <0.0, 1.0, 0.0>, 0.0, <0.0, 0.0, 0.0>, OC, <0.0, 0.0, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 1.0, 0.0, 0.0]);
if (OC == open) {
llSetTimerEvent(10);
g_OpenNow = TRUE;
} else {
llSetTimerEvent(0);
g_OpenNow = FALSE;
}
}

default
{
on_rez(integer param)
{
llResetScript();
}

state_entry()
{
open_close(close);
}

touch_start(integer total_number)
{
if (g_OpenNow == TRUE) // Prim is in open state, so calculate new 'closed' size
{
open_close(close);
}
else // Prim is in a closed (or undefined state), so calculate new 'open' size
{
open_close(open);
}
}

timer()
{
open_close(close);
}
}
SkydiverColorado Calloway
Registered User
Join date: 13 Apr 2008
Posts: 6
07-21-2008 05:09
Thanks so much for your help Qie and Ron! Ron that tweek you did worked perfect! Again, thanks a bunch!