script://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 == "unsheath"
{//llSay(0,"reveal"
;//restore visibility
llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES);
}else if(command == "sheath"
{//llSay(0,"hide"
;//make it invisible
llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES);
}
}
default
{
state_entry()
{
//set up a listener with no filters
llListen(6,"",llGetOwner(),""
;}
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("sheath",message);
checkForCommand("unsheath",message);
}
}
touch_start(integer total_number)
{
}
}