Automatically Close 1-prim cylindrical door
|
|
Hiroku Kamachi
Registered User
Join date: 29 Jul 2007
Posts: 10
|
10-16-2007 18:10
I am still a scripting n00b, so forgive me. I have a 1 prim cylider door that rotates around the Z-axis. I have to click a button to open and close it, but I want it to close on it's own so I don't have to click the button everytime. I use the following script: integer channel = -12; integer listen_handle; default { state_entry() { // initialize the listener // the listener will listen to everybody who touches the door-button (NULL_KEY) listen_handle = llListen(channel, "", NULL_KEY, ""); } listen(integer listen_channel, string name, key id, string message) { // only do something if the channel, where the message is received // is equal to our listen channel and if the message is «operate» if(listen_channel == channel && message == "operate") { // close or open the door (your original script) rotation rot = llGetLocalRot(); if (rot.z == 0) { rot.z = -0.707107; rot.s = 0.707107; } else { rot.z = 0; rot.s = 1; } llSetLocalRot(rot); } } } What should I add to make it close by itself? The script for the button is: integer channel = -12; // Always use negative numbers for Object to Object-talk default { state_entry() { // do nothing on rez } touch_start(integer total_number) { llSay(channel, "operate"); // Talk to the door } }
Any help will be appreciated.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-16-2007 18:21
Do you want it close on a timer or would you like it to use volume detect?
A timer is pretty straight forward.
Conversely you could put an invisible, "tape" or string barrier across the doorway that uses volume detect. Open the door. walk through the barrier and the collision event will set off a timer that will close it in something like 5 seconds?
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Hiroku Kamachi
Registered User
Join date: 29 Jul 2007
Posts: 10
|
10-16-2007 18:29
Either would be fine. I had a volume detect door on my old home and it worked great. Not having to press the button everytime would be wonderful.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-16-2007 19:51
If you are interested in using volume detect, then post how you think it should work and we will help you finish it. Doesn't matter if you think what you post is horrible. We are all horrible when we 1st start  It would give you an opportunity to dig around in the wiki some and exersize some brain cells. If you are completely lost on how to even start the code, then at least post an idea of how it should work without posting code. We'll have you up to being a top notch scripter in no time. integer channel = -12; integer listen_handle; rotation rot; float time = 5.0;//Set how long before door closes here
default { state_entry() { // initialize the listener // the listener will listen to everybody who touches the door-button (NULL_KEY) //The listener is actually listening for the button script, not an av. //rename the door button object to "button". It makes for a tighter listen listen_handle = llListen(channel, "button", NULL_KEY, ""); }
listen(integer listen_channel, string name, key id, string message) { // only do something if the channel, where the message is received // is equal to our listen channel and if the message is «operate»
//if(listen_channel == channel && message == "operate") //You will only get to here in the listen if the message was on listen_channel. //No use in testing for it. if(message == "operate") { // close or open the door (your original script) rot = llGetLocalRot(); if (rot.z == 0) { rot.z = -0.707107; rot.s = 0.707107; llSetTimerEvent(time); } else { rot.z = 0; rot.s = 1; } llSetLocalRot(rot); } } timer() { rot.z = 0; rot.s = 1; llSetLocalRot(rot); llSetTimerEvent(0.0); } }
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Hiroku Kamachi
Registered User
Join date: 29 Jul 2007
Posts: 10
|
10-16-2007 20:12
Well since I have no idea how to code the volume detect, I only know that it works, I will post how I think it should be. When I step on an invisible prim, the door should rotate 90 degrees, then once I step off the door closes after a set amount of time. That is how my old one works, except the prims slide, not rotate.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-16-2007 20:36
hahahahaha, OK you at least made an attempt and thought about it. I am about to go to bed but if no one posts it before tomorrow afternoon, I'll work up one and post it here. Using a collision event in a phantom prim will leave both your other scripts like they are now without the timer. The phantom prim will be a 3rd object with another script. When the collision event happens it will start a timer event just like in the script I posted but maybe only 2.0 seconds long or so. When the timer goes off then it will use a say just like the door button. Here is a little light reading until I can get back to you tomorrow: http://www.cheesefactory.us/lslwm/llVolumeDetect.htmI sent you to the wiki mirror because the main one is running kind of slow tonight. The description of llVolumeDetect is actually more confusing then it needs to be. It boils down to llVoumeDetect will automatically make the prim it is in phantom. Other then that is works about like touch. Hang in there. Believe it or not, all of this confusing scramble of words and functions do start to make since in a relatively short period of time.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Hiroku Kamachi
Registered User
Join date: 29 Jul 2007
Posts: 10
|
10-17-2007 14:33
The only script I can make is a rotation script that I can turn on and off. Everything else is too hard for me now.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-17-2007 14:42
From: Hiroku Kamachi The only script I can make is a rotation script that I can turn on and off. Everything else is too hard for me now. No problem Hiroku. You are starting to learn and will get better quickly. The easiest way to learn at first is example scripts of something you are interested in. Then you will begin to learn what each function does and the wiki entries start to make sense. I guess I was just mainly checking to see if you were just coming here to get a free script, which some people do. You have clearly shown that you are trying to learn. Noobs are always more then welcome here and we will be around to help as you progress. So many people spent hours answering my questions here when I first came. Now it is my turn to pay it forward. I'll code up something here in an hour or so and post it for you and throw in some comments so you can see what it is doing.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Hiroku Kamachi
Registered User
Join date: 29 Jul 2007
Posts: 10
|
10-17-2007 17:06
Ok, thank you. I do hope to learn more than just how to change a number in the script.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-17-2007 19:37
Other people may want to use this so we should pick a number different then -12: //This will generate a negative random channel between //-100000 & -999999 //Just place in a prim. It will say the channel number //and then it and the prim will vanish
default { state_entry() { integer channel = 0; { do { channel = ((integer) llFrand(3) - 1) * ((integer) llFrand(-999999)); } while(channel > -100000); } llOwnerSay((string)channel); llDie(); } }
Now for the good stuff: BUTTON: //Create a prim to use as the button //You could make 2 buttons, one for each side of the door //The button/buttons must be named exactly "button" //Place this script in it/them. To use //touch the button/buttons to open the door
//Use the channel from the random negative channel generator integer channel = -12;
default { touch_start(integer total_number) { llSay(channel, "open"); // Talk to the door } }
TRIPWIRE //Create a prim and put it in the dooorway, spanning the width //This prim must be named exactly "tripwire" //Place this script in it and it will turn it invisible and make it phantom //When someone walks through this prim it will cause a collision event //The collision event will say "close" to the door
//Use the channel from the random negative channel generator integer channel = -12;
default { state_entry() { llSetAlpha(0.0, ALL_SIDES); llVolumeDetect(TRUE);//Do not manually set this prim phantom. //llVolumeDetect will do it automatically } collision_start(integer total_number) { llSay(channel, "close"); } }
DOOR //Place this script in the door //it will open when the button is pushed & close when //the collision event is trigger in the tripwire
//Use the channel from the random negative channel generator integer channel = -12; rotation rot;
//Set how long you want the door to stay open after the collision event //with this timer. float tripwire_timer = 1.0;
//Just in case someone never walks through the door. It will close //automatically after this amount of time: float max_timer = 20.0;
default{ state_entry(){ //You are not going to be removing the listen so you do not need //to create listen handles. llListen(channel, "button", NULL_KEY, ""); llListen(channel, "tripwire", NULL_KEY, ""); }
listen(integer listen_channel, string name, key id, string message){ rot = llGetLocalRot(); if(name == "button" && message == "open"){ rot.z = -0.707107; rot.s = 0.707107; llSetLocalRot(rot); llSetTimerEvent(max_timer); } else if(name == "tripwire" && message == "close"){ llSetTimerEvent(tripwire_timer); } }
timer() { rot.z = 0; rot.s = 1; llSetLocalRot(rot); llSetTimerEvent(0.0); } }
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
10-17-2007 19:42
Sorry it took so long but it takes me 3 times as long to clearly comment as it does to just write the code  Whenever you are ready for going a little bit farther in your scripting I would highly suggest downloading LSLEditor. If you do, then go to that thread or give me a shout here and we will tell you how to download and install lslint into it as a plugin. It will make your scripting sooooo much easier and after you play with it then you can actually test a lot of your scripts or projects in it first. That is exactly what i did with this project. I created a project and then was able to touch the button to open the door and trigger the collision event to close it. lslint will tell you exactly where you have a mistake in a script. Enjoy and please keep scripting 
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Hiroku Kamachi
Registered User
Join date: 29 Jul 2007
Posts: 10
|
10-18-2007 00:53
thank you so much! I will put this in my doors and se how they react in the morning. I am too tired right now to worry about it.
|