Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

hide show script problems

Durandal Bosatsu
Registered User
Join date: 12 Oct 2007
Posts: 3
06-16-2008 05:11
i have another script that doesnt work for other people, can someone please fix this x_x
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)
{

}
}
Boreal Latte
Registered User
Join date: 15 Nov 2007
Posts: 104
06-16-2008 06:14
You mistake is often seen, so I will make the long story rather than the short.
When you attach an object from inventory, or when an object changes owner, the state_entry event will NOT be triggered, as the script is already in the default state.

Therefore, the problem is that you start listening for commands from you (the first time the script runs it will use the llGetOwner in the listen command - that owner is you as you have not yet given the object to others).

There are a number of ways to handle this
a) You can listen for when an object changes owner, using the "changed" event (see http://wiki.secondlife.com/wiki/Changed) - there is a specific change which is change of ownership - there you make the object listen to the new owner (see note below).
b) You can see who is the owner each time the object is rezzed using the "on_rez" event (see http://wiki.secondlife.com/wiki/On_rez).
b) If the object is an attachment, there is also the "attach" event (see http://wiki.secondlife.com/wiki/Attach)

Some suggest to use the http://wiki.secondlife.com/wiki/LlResetScript function in those cases. It is kind of crude, as it will reset all data of the script and is not particular efficient. On the other hand, ownership change does normally not happen many times a second, so it is OK.

If you instead want to not reset the script, but merely change the listener, then you need to remove the old owner from the listener, and then add the new. It works as follows
i) Notice that the llListen command returns an integer - that number can be used to remove the old listener - remember that in a variable - say "old_owner".
ii) When a new owner is detected, remove the old owner from the listener list using http://wiki.secondlife.com/wiki/LlListenRemove

That you are not the first to run into this can be seen from the Wiki under the caveats of llListen:
"Once a listen is registered it's filters cannot be updated, if the listen is register to llGetOwner, the listen will remain registered to the old owner upon owner change.
Owner change can be detected with the changed event.
To work around this the old listen will need to be closed and a new one opened for the new owner."

If none of this makes sense, I am sorry, send me an IM and I'll help you out in-world.
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-16-2008 06:37
This version anybody can use:
CODE

//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,"",NULL_KEY,"");
}

listen(integer channel, string name, key id, string message)
{
//llSay(0,"listening");
//make a key called 'me'
//only listen to me!
checkForCommand("sheath",message);
checkForCommand("unsheath",message);
}

touch_start(integer total_number)
{

}
}
Hppy scripting
_____________________
From Studio Dora