CODE
// Coded Door
// Wednesday Grimm
// June 10, 2003
//
// This script is for a door with a 3 number code chosen from 6
// numbered buttons.
//
// The object is door and a set of linked buttons. The
// door is the primary object in the link set and contains this
// script.
//
// The buttons are numbered and there is a code to open the door. If
// the buttons are pressed in the right order, the door goes phantom and
// partially transparent for a short time.
// This is the code to open the door, "123", very complex
integer code1 = 1;
integer code2 = 2;
integer code3 = 3;
// This is the queue that holds the last 3 buttons pressed, we could use
// a list to do this, but this is simpler.
integer queue1;
integer queue2;
integer queue3;
// This list gives the translation between link numbers and the
// value of the button. In this case, the 7th link is the "1" button
list link_trans = [
0,
0,
6, // link number 1
5, // 2
4, // 3
3, // 4
2, // 5
1 // 6
];
// This is true if the door is open
integer open;
// How long to stay open, in seconds
float timeout = 5.0;
// close the door
doClose()
{
open=FALSE;
llSetStatus(STATUS_PHANTOM, FALSE);
llSetAlpha(1.0, ALL_SIDES);
}
// open the door, set a timer to close the door
doOpen()
{
open=TRUE;
llSetStatus(STATUS_PHANTOM, TRUE);
llSetAlpha(0.5, ALL_SIDES);
llSetTimerEvent(timeout);
}
// If the last 3 buttons pressed match the code, open the door
checkQueue()
{
if (
queue1 == code1 &&
queue2 == code2 &&
queue3 == code3)
{
doOpen();
}
}
// add a number to the queue, shift other 2 numbers down
enqueue(integer num)
{
queue1 = queue2;
queue2 = queue3;
queue3 = num;
}
default
{
state_entry()
{
queue1 = 0;
queue2 = 0;
queue3 = 0;
doClose();
}
touch_start(integer total_number)
{
// figure out which like was touched then translate that
// to a button value.
integer num = llList2Integer(link_trans, llDetectedLinkNumber(0));
if (num != 0 && !open)
{
llTriggerSound("click", 0.5);
enqueue(num);
checkQueue();
}
}
timer()
{
// turn off the timer and close the door
llSetTimerEvent(0.0);
doClose();
}
}