scottdolphin Posted February 24, 2019 Share Posted February 24, 2019 I have been looking for a simple password door script with an autoclose function. Does anyone have any suggestions. I could also use a badge access script that will allow users to enter certain areas only if they are wearing the correct 'badge' or combination of 'badges'. I am building a gamified immersive curriculum and need to create areas that can only be accessed once specific tasks or assignments are complete. I have a general grasp of LSL and can script simple functions but use small words please...🙂 Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 24, 2019 Share Posted February 24, 2019 (edited) So, you have a three part challenge: 1. Write the door script. There are many ways to do that, summarized in the sticky thread at the top of this forum. You'll find suggestions for the other two challenges if you dig through things there too. 2. Make it password protected. Again, several possibilities. One of the many ways is to open a text box when someone clicks to activate the door and ask the person to type the secret word in it. 3. Make the door autoclose. If you don;t see a ready solution among the suggestions in the sticky thread or the Library, all you really need to do is start a 10-second timer when the door opens. When the timer fires, make it close the door, using the same code that you would use for closing it if someone had clicked to close the door. (Well, not quite all you need to do. You should also deactivate the touch_start event until the timer fires, to keep someone from clicking the opened door.) So: touch_start(integer num) { if ( !iTouched ) { iTouched = TRUE; // so, now nobody can touch the door //Open the door llSetTimerEvent(10.0); } } timer() { llSetTimerEvent(0.0); // Stop the timer //Close the door iTouched = FALSE; // And reactivate the touch_start event } Oh, and remember to define iTouched as a global integer variable. Edited February 24, 2019 by Rolig Loon Link to comment Share on other sites More sharing options...
scottdolphin Posted February 25, 2019 Author Share Posted February 25, 2019 I will give it a try. thanks Link to comment Share on other sites More sharing options...
scottdolphin Posted March 2, 2019 Author Share Posted March 2, 2019 so this is my open and closed script. Where would I put the password text box? I keep getting syntax errors default //initially closed { touch_start(integer num_detected) { state open; } } state open { state_entry() { rotation r1 = llEuler2Rot(<0.0,0.0,90.0> * DEG_TO_RAD); llSetRot(r1 * llGetRot()); } touch_start(integer num_detected) { state closed; } } state closed { state_entry() { rotation r2 = llEuler2Rot(<0.0,0.0,-90.0> * DEG_TO_RAD); llSetRot(r2 * llGetRot()); } touch_start(integer num_detected) { state open; } } Link to comment Share on other sites More sharing options...
scottdolphin Posted March 2, 2019 Author Share Posted March 2, 2019 BTW...I am using this on the root hinge prim. The door was created by another user and I have added the above rotate script Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 2, 2019 Share Posted March 2, 2019 (edited) We do not normally provide complete scripts here, but this is one of those rare cases when I think an example might help. Here it is, followed by a little explanation: key kAv; integer iChan; integer iLsn; integer iOpenSesame; string strPass = "Password"; // Yeah, like you are really going to make "Password" your secret code ... default //initially closed { state_entry() { llListenRemove(iLsn); // Close the listen handler each time you retyurn to state default iChan = (integer)llFrand(1000000.0); iLsn = llListen(iChan,"","",""); //Re-open the listen handler with a fresh channel # } touch_start(integer num_detected) { kAv = llDetectedKey(0); state open; } } state open { state_entry() { llTextBox(kAv," \nType your passcode and then \"Submit\" ", iChan); } listen( integer channel, string name, key id, string message) { if (strPass == message) { iOpenSesame = TRUE; } } touch_start(integer num_detected) { if (iOpenSesame) { iOpenSesame = FALSE; rotation r1 = llEuler2Rot(<0.0,0.0,90.0> * DEG_TO_RAD); llSetRot(r1 * llGetRot()); state closed; } else { llRegionSayTo(kAv,0,"Nope. Wrong passcode."); state default; } } } state closed { state_entry() { // There's no real need for a state_entry event here unless you want to autoclose the door // If so, uncomment the next line and remove the touch_start event // llSetTimerEvent(10.0); } timer() { llSetTimerEvent(0.0); rotation r2 = llEuler2Rot(<0.0,0.0,-90.0> * DEG_TO_RAD); llSetRot(r2 * llGetRot()); state default; } touch_start(integer num_detected) { // No need for a passcode here. The door is already open rotation r2 = llEuler2Rot(<0.0,0.0,-90.0> * DEG_TO_RAD); llSetRot(r2 * llGetRot()); state default; } } First, I would almost never recommend using multiple states for a script like this, but since you started there, I'm building on your start. Second, the usual disclaimer applies: There is no guarantee that scripts and snippets posted in this forum are free of errors. They have generally not been tested in world, and are offered only as "blackboard" examples, written quickly for illustration. In this particular case, I have not made any attempt to optimize the script to make it more compact or efficient. It is what it is, just for illustration. Notice that you only need to ask for the passcode to open the door, so the verification is only in state Open. I'd suggest closing the door on a timer after you open it, unless you want it to just stay open until someone bothers to close it -- which kind of defeats the purpose of the passcode. As you study the example, pay attention to why the flow goes back to state default when the door closes and if there's a passcode error. Also, be sure that you understand when the boolean iOpenSesame variable changes state from FALSE to TRUE and back. A basic script like this usually needs extra bells and whistles to make it truly useful. For example, ask yourself how to give each potential user a unique passcode instead of using the same passcode for everyone. Or how to add sounds. Or use something other than a touch to trigger the door, like a sensor. Or rewrite it without using multiple states. EDIT: Final note. When you post a script here, it really helps to indent it carefully. Not only does it make the script more readable, it usually helps you see where you may have made basic coding errors like mismatched brackets. Yours was error free, but still ... AND ANOTHER SMALL EDIT: I added a line to close the listen handler at the top of state_entry in state default. Otherwise, you'd be opening a fresh channel each time anyone clicks the door. [I did say there were no guarantees that the scripts posted here are flawless. ] 😉 Edited March 2, 2019 by Rolig Loon 2 Link to comment Share on other sites More sharing options...
scottdolphin Posted March 2, 2019 Author Share Posted March 2, 2019 Thank you. I REALLY appreciate this. I am trying to cover a lot of ground in a very short span of time for this project. 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted March 2, 2019 Share Posted March 2, 2019 See my second edit above ^^ Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now