Jump to content

Trigger command on attach, trigger different command on detach for owner only


Rhemah
 Share

You are about to reply to a thread that has been inactive for 3294 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

default
{
    attach(key id)
    {
        if (id)   
        {
            llRegionSayTo(id,105, "commandtotriggerone");//this works
        }
        else
        {
            llRegionSay(105,"commandtotriggertwo"); //this does not work
        }
    }
}

//I simply want to make command to the wearer(owner) to trigger something when an object is attached and when the wearer(owner) detach it i want to make a command also to trigger something different; however, my idea does not seem to work at all, i'm a little confuse how to do it. a little help pls =(
Link to comment
Share on other sites

Your logic is correct, that is how you separate an on-attach code from on-detatch code. However, llRegionSayTo requires three parameters: The key of the recipient, the channel, and the message. In your posted code you are missing the key parameter in both cases calls to llRegionSayTo, so your code will not compile.

Link to comment
Share on other sites

The code you reproduce can't be what you have, if something is working.   That wouldn't even compile.

llRegionSayTo(), which is what you have there, takes three arguments:  uuid of the person or object you're saying it to, channel you're saying it on, and the message.

llRegionSay()  takes two arguments :  channel and message, as you have in your code.

Please take a look at your original code and see what you actually do have.

Other than that, the code looks OK to me.   If you are, in fact, using llRegionSay(), then I thing it should work.    I know that there's only a limited window for code to execute when you detach something, before it goes back into your inventory, but it should give you enough  time to execute a simple communication function.

Are you sure that the receiving script -- the one that should respond to the message "commandtriggertwo -- is working properly?

 

ETA  Adeon beat me to it.

Link to comment
Share on other sites

 

//Reciever of messageinteger Channel_This;default{    state_entry()    {        Channel_This = llListen(105,"",NULL_KEY,"");         key id = llDetectedKey(0);    }    listen(integer chan, string name, key id, string msg)    {                  if(llGetOwnerKey(id) == llGetOwner() && chan = 105)        {            if(msg = "commandtotriggerone")            {            llWhisper(0, "iget ONE");            }                    else if (msg = "commandtotriggertwo")             {            llWhisper(0,"iget TWO");            }        }    }}
//Giver of messagedefault{    attach(key id)    {        if (id)           {            llRegionSayTo(id,105,"commandtotriggerone");        }        else        {            llRegionSay(105,"commandtotriggertwo");        }    }}

 i tried this one, but i can't seem to understand why it does not receive the message. 

I want it to work only to the owner so if ever everyone in the sim is wearing the same "Reciever of message"  not everyone will receive the "commandtriggertwo"

 

Link to comment
Share on other sites

If the chatting object is already deleted by the time the listener processes the message, then the llGetOwner test won't work.

If the listener also happens to be an attachment, you can send the chat to the owner, and in that case it will get to the attachment too. If your goal is more to prevent crosstalk than an attempt at authentication, that may be all you need.

Link to comment
Share on other sites

You are confusing single "=" signs with double ones.   The single = sign is used in LSL to assign a value. That is, x = 10; sets the value of x to 10.    The double == sign tests for equality.   That is, if (x==10) returns TRUE if the value of x is 10 and FALSE if it isn't.

It's a very easy typo to make, particularly when you're tired.

Anyway, the code in the receiver should be

//Reciever of messageinteger Channel_This;default{	state_entry()	{		Channel_This = llListen(105,"",NULL_KEY,"");		// key id = llDetectedKey(0);  unnecessary, and meaningless here	}	listen(integer chan, string name, key id, string msg)	{		if(llGetOwnerKey(id) == llGetOwner() && chan == 105)			//you don't need to check the channel, since that's the only one you're listening on, but if you do it's if chan == 105, not if chan = 105		{			if(msg == "commandtotriggerone")//NOT if msg = "commandtotriggerone"			{				llWhisper(0, "iget ONE");			}			else if (msg == "commandtotriggertwo") // again, NOT if msg = something			{				llWhisper(0,"iget TWO");			}		}	}}

Additionally,  I would suggest storing the wearer's uuid in the sender, so you can use llRegionSayTo both when the item is attached and detached.  Thus:

key wearer; //because it's declared up here, wearer is a global value and can be used anywhere in the script//Giver of messagedefault{    attach(key id)    {        if (id)   	{	    wearer = id;            llRegionSayTo(wearer,105,"commandtotriggerone");        }        else        {            llRegionSayTo(wearer,105,"commandtotriggertwo");        }    }}

Try this, particularly the corrected code for the receiver, and see how you get on.

If that doesn't work, follow Cerise's suggestion -- actually, follow it anyway, but we might as well check what exactly the problem was first -- and remove both the test for the channel and for ownership from the listen event.   If you're storing the owner's uuid in the sender device, using the global key wearer, and using llRegionSayTo, only items the owner is wearing (or sitting on) can hear the message.

Link to comment
Share on other sites

Is the listening object supposed to be attached to the avatar?

The problem, as Cerise says, is that by the time the receiving object tries to check if (llGetOwnerKey(id)==llGetOwner()) the id it's checking is no longer valid, because the sending object no longer exists on the region.

This means you have to find a workround.

If the owner is wearing the listening object as well as the object you are detaching, you can safely remove the test llGetOwnerKey(id) and have the object use llRegionSayTo(owner, channel, message) when attached and detached.   That's because, no matter how many other devices are listening on the region, only objects attached to the wearer will hear them.   That works.   I've tried it just now.

If, however, the listening object is not attached to the owner, probably the neatest way round the problem is going to be to use a userfunction like Key2Number in the wiki to generate a channel for the objects to use, based on their owner's uuid.   That's going to be unique on the region, particularly if you add an offset to it (that is, add 30 to the number, or something) in case any other objects are using the same method.

Alternatively, you could have the object say its owner's uuid when it's detached, and have the receiving script check to see if that's the same as its own owner's uuiid.    In that case, it's probably safest to cast things explicitly, thus: if((key)message==llGetOwner()).   

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3294 days.

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
 Share

×
×
  • Create New...