Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Coded door

Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
06-10-2003 19:12
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();
}
}
_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
07-13-2004 10:23
A few people have IM'ed me about this script.

To use this script, you need a main "door" object linked to six "buttons". Presumably, each button will have a number texture or something on it. You could use XyText to do this.

This script goes in the main door object.

Because of the nature of link-sets and whatnot, you'll need to edit this script to use it. You need to figure out which link number corresponds to which button. You can do this by adding a line like this to the touch_start() event, then taking it out once you've got it figured out:

llSay(0, "You touched link number " + (string)llDetectedLink(0));

So, you click on all the buttons, you figure out that button number 1 is (for example) link number 4, so you would set the 5th element (5th because we start counting from 0) of link_trans to 1.
_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!