Jump to content

Door script 0.2

From OSgrid Wiki
Revision as of 20:50, 20 July 2018 by Osgridadmin (talk | contribs) (Created page with "<source lang=lsl> /* Fu's talking door script v0.2 - locking door latch - "CONSTANTS" for code clarity v0.1 - state changes - passing data betw...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<source lang=lsl>

/*

   Fu's talking door script 
   v0.2
   - locking door latch
   - "CONSTANTS" for code clarity
   v0.1
   - state changes
   - passing data between states
   - llListen() and listen event handler
   v0.0
   - basic states
   (c)2017 - Fu Barr (OSGrid)
  • /

integer DEBUG = FALSE;

string code_lock = "Lockus locke"; string code_unlock = "Unlockus locke";

string latch;

string txt_unlocked = "This door is now unlocked."; string txt_locked = "This door is now locked."; string txt_noentry = "Locked. Your pixels may not pass!"; string txt_welcome = "Welcome, ";

key avatar_uuid;


default {

   on_rez(integer r) {
       llResetScript();
   }
   state_entry() {
       latch = "UNLOCKED";
       llOwnerSay("running " + llGetScriptName());
       state closed;
   }

}


state closed {

   state_entry() {
       llListen(0, "", NULL_KEY, code_unlock);     // using two llListen() for early channel 0 chat filter
       llListen(0, "", NULL_KEY, code_lock);
   }
   touch_end(integer t){
       if(latch == "LOCKED") {
           llSay(0, txt_noentry);
       } else {
           avatar_uuid = llDetectedKey(0);
           state open;
       }
   }
   listen(integer channel, string name, key uuid, string msg) {
       if(DEBUG){llOwnerSay("closed::listen() key: " + uuid);}
       if(msg == code_unlock){
           latch = "UNLOCKED";
           llSay(0, txt_unlocked);
       } else if(msg == code_lock) {
           latch = "LOCKED";
           llSay(0, txt_locked);
       }
   }
   state_exit() {
       // TODO: swing door open
   }

}


state open {

   state_entry() {
       llSay(0, txt_welcome + llKey2Name(avatar_uuid));
       state closed;
   }
   state_exit() {
       // TODO: swing door shut
   }

}

</source>