Hide/show script
This script is from my (Wheelo Schomer's) hat. It only accepts commands from the owner.
It checks for the commands "reveal hat" and "hide hat". It then sets the alpha property of the object to 0 or 1.
Some of the comments are for debugging (the llSay ones).
//declare 'checkForCommand' function (checks if a command was said) checkForCommand(string word,string sentence){ //llSay(0,"checking for word " +word); //change the sentence to lowercase string lowerSentence = llToLower(sentence); string command = llToLower(word); //llSay(0,"word is now " +word); //check if the command was found in the sentence integer foundCommand = llSubStringIndex(lowerSentence,command); //if it is not found, llSubStringIndex returns -1 //so if it is not -1, the command must have been said if(foundCommand != -1){ //llSay(0,"found"); //call function 'doCommand', pass variable 'command' doCommand(command); } } //declare function 'doCommand' (hides/reveals) doCommand(string command){ if(command == "reveal hat"){ //llSay(0,"reveal"); //restore visibility llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES); }else if(command == "hide hat"){ //llSay(0,"hide"); //make it invisible llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES); } } default { state_entry() { //set up a listener with no filters llListen(0,"",NULL_KEY,""); } listen(integer channel, string name, key id, string message) { //llSay(0,"listening"); //make a key called 'me' key me = llGetOwner(); //only listen to me! if(id == me){ checkForCommand("hide hat",message); checkForCommand("reveal hat",message); } } touch_start(integer total_number) { } }
This is a fairly generic script that can be used anywhere.
Right now, I can't think of an application...except for my hat!
To personalise it, just change the 'reveal hat' and 'hide hat' in the listen function and 'doCommand' function to words of your choice.
Note: this was intended for linked prims. May or may not work for single prims.
- if you are communicating between linked sets you shouldn't really be setting up a listener, you simply use linked messaging (check out LSL Wiki, I can point you in the right direction if need be, just ask). As and when you DO have to use listen commands, it is good practice NOT to listen on channel 0 (the public channel). Listeners ramp up the processor demand on the island, but better use of filters improves this. As such I ususally use something like this when declaring the listener: llListen(93,"",llGetOwner(),""); In this way you then communicate by typing: /93 reveal hat The load on the island is much reduced because you've narrowed the scope of the listener on declaration, not by doing checks later on. I hope that makes sense, but if not just let me know. -- Woop
- OK, so when the script hears me say 'reveal hat' it could use link_message() instead of listen(). But how would it know when to call link_message()? -- Wheelo Schomer
- I was thinking of your "note: this was intended for linked prims" when I added the comment. Clearly if you are communicating with a single prim which is changing itself then yes, it needs a listener (although do take note of my comments regarding listener declaration). If a single prim is listening to you but then communicating to other prims within a linked set, that's when you'd want to use linked set communications (as opposed to lots of listeners). I hope that's much clearer. -- Woop
- OK, so when the script hears me say 'reveal hat' it could use link_message() instead of listen(). But how would it know when to call link_message()? -- Wheelo Schomer
If you can do away with checking for the commands as part of larger sentences I would probably re-write the code thus (incorporating the more specific listener filters). This re-write also changes to working on a single prim containing the script.
default { state_entry() { //set up a listener with channel and owner filters llListen(94,"",llGetOwner(),""); } listen(integer channel, string name, key id, string message) { string lowermessage = llToLower(message); if (lowermessage=="hide hat") llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES); else if (lowermessage==""reveal hat"") llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES); } }
- Well that is a whole lot simpler!
- However, you would need to put this in every prim in the set. My script above only needs to be put in one prim, and it changes all the other prims in the set (which don't have any scripts); therefore you only need one listener. Wheelo Schomer
- Fair call. I've modified my mini-script back to using llSetLinkAlpha() -- Woop