Jump to content

say command on object attach/detach


EztliLyre
 Share

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

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

Recommended Posts

ive been fiddling with this for a while never done coding on second life before. im trying to get this script to run when i take off and put on a object which it does but its supposed to then make me say a chat command in channel 5 to make another script do things

 

default
{
    attach(key attached)
    {
        
        if (attached == NULL_KEY)  // object has been detached
        {
            llSay(5,"soft");
            // etc.
        }
        else   // object has been //attached//
        {
            llSay(5,"hide");
            // etc.
        }
        
    }
}

 

basically what it should do is when object is attached make me say /5 hide and when object is detached make me say /5 soft

Link to comment
Share on other sites

There is at least one problem here, and maybe two.  The major one is purely logical.  No scripted object is going to be able to say anything after it is detached.  It doesn't exist any more, so it can't send messages.  The other potential problem -- maybe not important in this case --- is a due to a scripting limitation in Second Life.  A scripted object cannot listen to itself, except in the special case of listening to the responses from a llDialog or llTextBox.  So, if your other script -- the one that will be listening on channel 5 -- is in the same object, it will never hear the word "hide".

So, you have a few options.  If you really want to do something with the message "soft" as your object detaches, you might send the message, wait a fraction of a second, and then detach it.  That would mean using a non-standard way of detaching the object instead of just right-clicking and selecting "Detach".  Maybe you could use a dialog.  Or you might modify the receiving script to check every once in a while to see if your wearable object is still there.  If it's not, then it can pretend that it heard "soft". 

If your receiving script is in the same object, you can use a link message instead of llSay.

You didn't say anything about that other script, but I assume that it really is listening on channel 5, and that it isn't filtering messages so that it only hears -- for example -- messages that you send personally.

Link to comment
Share on other sites


EztliLyre wrote:

basically what it should do is when object is attached make me say /5 hide and when object is detached make me say /5 soft

 That's your problem.   It's not you saying /5 soft or /5 hide.    It's the object.   Presumably the other item is listening out for a command from its owner, not another object,

So, what's the solution?

Two possibilities.   If the listening object is also attached to you (or if you're sitting on it), you could use llRegionSayTo(llGetOwner(),5,"soft"),    This works because objects attached to an avatar can hear messages sent to that avatar's UUD if they're listening on that channel.

If that's not possible, then you need to change the listener in the listening object from llListen(5,"",llGetOwner(),"") to an open listener -- llListen(5,"","","") and then, in the listen event, use the following test:

	listen(integer channel, string name, key id, string message)	{		if(llGetOwnerKey(id) == llGetOwner()){			//then do stuff		}	}

In English, that means "if the uuid of whatever I've just heard from belongs to my owner or is my owner (avatars own themselves as far as LSL is concerned, whatever they may think in Gor), and will filter out commands issued by other people's attachments.

While I hesitate to disagree with Rolig, I think you can probably get away with sending the "hide" message when you detach the item.   This is because there is a small window for scripts to do things in between the item being detached and it returning to your inventory.    You certainly don't have time to do very much, but a simple llSay should be safe enough.

Up until about a year ago, I would have said, too, that saying things when you detach something wouldn't work, but then I was discussing this with a very experienced scripter, who said that for years he's been having attachments say stuff on being detached, and it's not let him down yet.   After that conversation I've been trying it, and it seems reliable to me.

If you don't want to risk that, or if the "//etc" is a lot of code, you could try grabbing the speaking object's uuid when you hear the attach message, and then run a timer checking for llGetObjectDetails(id,[OBJECT_ATTACHED_POINT]).   Assuming the speaking object is not a HUD, then if the llGetObjectDetails call returns an empty list, then you know the speaking object is no longer there.

 

 

Link to comment
Share on other sites

thanks for the help guys im gonna try this stuff, as for the "etc" part i was using a template code i found which was working perfeclty fine but as you said it doesnt make me say stuff it makes the object say stuff.

an idea i just had is maybe make some kind of relay script in something that wont detatch that will hear a command from the removed object then relay it to the other stuff?

Link to comment
Share on other sites

How would it be if you simply said /5 hide and then your attachment detaches itself.   Anything else in earshot will hear /5 hide too, and can do whatever it's supposed to do independently of your attachment?

That is, in the listen event, if your attachment hears "hide" it does the template stuff, then when it's finished with that it calls 

llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);

and then, in the run_time_permissions event, it detaches itself? 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2619 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...