Very elaborate airlock
From The Schommunity Wiki
This is an airlock that has two sets of sliding doors that open in turn when a button is pressed. If the sets of doors are labelled door1a and door1b, and door2a and door2b then a button is needed outside of each set of doors, button1 and button2. There are also a set of lights one inside and one outside of each door, which change colour when the doors open. AND there is a button inside that can be pressed if someone gets stuck. It is all controlled with a controller prim that sends lots of linked messages and must be the ROOT PRIM. So, in summary you need a prim with each of these names:
controller
door1a
door1b
door2a
door2b
button1
button2
inner_button
outer_sign1
inner_sign1
outer_sign2
inner_sign2
This works by linked messages to between prims, so the naming is very important here.
This goes in the controller.
//Airlock_controller_v1.0
//21/1/08
//Made by Olly Butters for the schome project.
//Follows approximately this routine:
//A button press invokes the controller
//Controller turns buttons red and turns it off
//Controller opens the doors on the side the button was pressed.
//Controller sleeps
//Controller closes the doors.
//Controller starts the scanning process
//Controlelr sleeps.
//Controller opens other doors.
//Controller sleeps.
//Controller closes doors.
//Controller turns buttons back to green and on again.
//NOTE: prim names MUST follow the naming convension below. With '1's being together and '2's being together.
integer PRIM1; //door1a
integer PRIM2; //door1b
integer PRIM3; //door2a
integer PRIM4; //door2b
integer PRIM5; //button1
integer PRIM6; //button2
integer PRIM7; //outer_sign1
integer PRIM8; //inner_sign1
integer PRIM9; //outer_sign2
integer PRIM10; //inner_sign2
//integer PRIM11; //scanner
integer PRIM12; //inner_button
integer first_door_a;
integer first_door_b;
integer second_door_a;
integer second_door_b;
integer first_outer_sign;
integer first_inner_sign;
integer second_outer_sign;
integer second_inner_sign;
//Function to get the numbers of all the linked prims.
getLinkNums()
{
integer i;
integer linkcount=llGetNumberOfPrims();
//llSay(0, "There are "+(string)linkcount +" prims");
for (i=1;i<=linkcount;++i)
{
string str=llGetLinkName(i);
if (str=="door1a") PRIM1=i;
if (str=="door1b") PRIM2=i;
if (str=="door2a") PRIM3=i;
if (str=="door2b") PRIM4=i;
if (str=="button1") PRIM5=i;
if (str=="button2") PRIM6=i;
if (str=="outer_sign1") PRIM7=i;
if (str=="inner_sign1") PRIM8=i;
if (str=="outer_sign2") PRIM9=i;
if (str=="inner_sign2") PRIM10=i;
//if (str=="scanner") PRIM11=i;
if (str=="inner_button") PRIM12=i;
}
}
default
{
state_entry()
{
//llSleep(3);
//llSay(0, "starting the initialization");
//Get the prim numbers and make sure they are initialised properly.
getLinkNums();
//llSleep(1);
llMessageLinked(PRIM1,0,"closed","");
llMessageLinked(PRIM2,0,"closed","");
llMessageLinked(PRIM3,0,"closed","");
llMessageLinked(PRIM4,0,"closed","");
llMessageLinked(PRIM5,0,"closed","");
llMessageLinked(PRIM6,0,"closed","");
llMessageLinked(PRIM7,0,"closed","");
llMessageLinked(PRIM8,0,"closed","");
llMessageLinked(PRIM9,0,"closed","");
llMessageLinked(PRIM10,0,"closed","");
//llMessageLinked(PRIM11,0,"closed","");
llMessageLinked(PRIM12,1,"","");
}
//triggered from a button press
link_message(integer source, integer which_door, string str, key id)
{
if(source==PRIM12)//ie the inner button. used as emergency button if stuck on the inside.
{
source=PRIM5; //make it think button1 was pressed
}
//this switch allows the correct doors to be opened.
if(source==PRIM5)//ie button1
{
first_door_a = PRIM1;
first_door_b = PRIM2;
second_door_a = PRIM3;
second_door_b = PRIM4;
first_outer_sign = PRIM7;
first_inner_sign = PRIM8;
second_outer_sign = PRIM9;
second_inner_sign = PRIM10;
state open_1;
}
if(source==PRIM6)//ie button2
{
first_door_a = PRIM3;
first_door_b = PRIM4;
second_door_a = PRIM1;
second_door_b = PRIM2;
first_outer_sign = PRIM9;
first_inner_sign = PRIM10;
second_outer_sign = PRIM7;
second_inner_sign = PRIM8;
state open_1;
}
}
}
//OPEN DOOR SET 1
state open_1
{
state_entry()
{
//turn the buttons off
llMessageLinked(PRIM5,1,"red","");
llMessageLinked(PRIM6,1,"red","");
llMessageLinked(PRIM12,0,"red","");
//Open doors 1a and 1b
//llSay(0, "about to tell doors to open");
llMessageLinked(first_door_a,1,"open","");
llMessageLinked(first_door_b,1,"open","");
//sort out the signs
llMessageLinked(second_inner_sign,1,"red","");
llMessageLinked(second_outer_sign,1,"red","");
llSleep(5);
state close_1;
}
}
//CLOSE DOOR SET 1
state close_1
{
state_entry()
{
llMessageLinked(first_door_a,0,"closed","");
llMessageLinked(first_door_b,0,"closed","");
llMessageLinked(first_inner_sign,1,"red","");
llMessageLinked(first_outer_sign,1,"red","");
state scanning;
}
}
state scanning
{
state_entry()
{
//llMessageLinked(PRIM11,1,"go","");
//llSay(0, "wait for some kind of scanning jobbie to finish");
llSay(-9, "start");
llSleep(6);
state open_2;
}
//link_message(integer source, integer which_door, string str, key id)
//{
// state open_2;
//}
}
//OPEN DOOR SET 2
state open_2
{
state_entry()
{
llMessageLinked(second_door_a,1,"open","");
llMessageLinked(second_door_b,1,"open","");
llMessageLinked(second_inner_sign,0,"green","");
llMessageLinked(second_outer_sign,0,"green","");
llSleep(5);
state close_2;
}
}
//CLOSE DOOR SET 2
state close_2
{
state_entry()
{
//close doors 2a and 2b
llMessageLinked(second_door_a,0,"closed","");
llMessageLinked(second_door_b,0,"closed","");
//turn the buttons back on
llMessageLinked(PRIM5,0,"closed","");
llMessageLinked(PRIM6,0,"closed","");
//reset the sign
llMessageLinked(first_outer_sign,0,"green","");
llMessageLinked(first_inner_sign,0,"green","");
llResetScript();
}
}
This goes in the doors, edit this so the doors open in opposite directions by changing the open_by parameter
//linked_door_v1.0
//part of the airlock
//olly butters 21/01/08
//The starting pos will have to be hardwired in incase the sim crashes and it resets with the doors open.
vector starting_position;
vector open_by = <-4.8, 0.0, 0.0>; //amount and direction to open by
default
{
state_entry()
{
starting_position = llGetLocalPos(); //quick hack, needs real coords.
//llSay(0,"Starting pos" + (string)starting_position);
state waiting_for_message;
}
}
state waiting_for_message
{
state_entry()
{
}
link_message(integer source, integer num, string str, key id)
{
if(num==0)
{
state closed;
}
if(num==1)
{
state open;
}
}
}
state closed
{
state_entry()
{
llSetPos(starting_position);
state waiting_for_message;
}
}
state open
{
state_entry()
{
vector open_position = starting_position+open_by;
llSetPos(open_position);
//llSay(0, "Should open to="+(string)open_position);
//llSay(0, "Now at =" +(string)llGetLocalPos());
state waiting_for_message;
}
}
This goes in the inner button.
//inner button v1.0
//part of the airlock
//olly butters 19/1/08
//kicks off the whole process.
vector untouched_prim_colour = <0,1,0>; //green
vector touched_prim_colour = <1,0,0>; //red
default
{
state_entry()
{
llSetColor(untouched_prim_colour, ALL_SIDES );
}
link_message(integer source, integer num, string str, key id)
{
//change the colours to reflect on/off status
if(num==1)
{
state on;
}
if(num==0)
{
state off;
}
}
}
state on
{
state_entry()
{
llSetColor(untouched_prim_colour, ALL_SIDES );
}
touch_start(integer temp)
{
llMessageLinked(LINK_ROOT,1,"open",""); //talk to the root prim
}
link_message(integer source, integer num, string str, key id)
{
//change the colours to reflect on/off status
if(num==1)
{
state on;
}
if(num==0)
{
state off;
}
}
}
state off
{
state_entry()
{
llSetColor(touched_prim_colour, ALL_SIDES );
}
link_message(integer source, integer num, string str, key id)
{
//change the colours to reflect on/off status
if(num==1)
{
state on;
}
if(num==0)
{
state off;
}
}
}
This goes in each of the signs.
//sign colours v1.0
//olly butters 19/01/08
//sets the colour of the signs depending on the recieved message.
vector untouched_prim_colour = <0,1,0>; //green
vector touched_prim_colour = <1,0,0>; //red
default
{
state_entry()
{
state waiting_for_message;
}
}
state waiting_for_message
{
link_message(integer source, integer num, string str, key id)
{
if(num==0)
{
state closed;
}
if(num==1)
{
state open;
}
}
}
state closed
{
state_entry()
{
llSetColor(untouched_prim_colour, ALL_SIDES );
state waiting_for_message;
}
}
state open
{
state_entry()
{
llSetColor(touched_prim_colour, ALL_SIDES );
state waiting_for_message;
}
}
This goes in each of the EXTERNAL buttons.
//button v1.0
//part of the airlock
//olly butters 19/1/08
//kicks off the whole process.
vector untouched_prim_colour = <0,1,0>; //green
vector touched_prim_colour = <1,0,0>; //red
default
{
state_entry()
{
llSetColor(untouched_prim_colour, ALL_SIDES );
}
touch_start(integer total_number)
{
state touched;
}
link_message(integer source, integer num, string str, key id)
{
//change the colours to reflect on/off status
if(num==1)
{
llSetColor(touched_prim_colour, ALL_SIDES );
}
if(num==0)
{
llSetColor(untouched_prim_colour, ALL_SIDES );
}
}
}
state touched
{
state_entry()
{
llMessageLinked(LINK_ROOT,1,"open",""); //talk to the root prim
}
link_message(integer source, integer num, string str, key id)
{
//change the colours to reflect on/off status
if(num==1)
{
llSetColor(touched_prim_colour, ALL_SIDES );
}
if(num==0)
{
llSetColor(untouched_prim_colour, ALL_SIDES );
state default;
}
}
}