Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Proper Way to Detect Attach to Owner?

Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
10-29-2004 10:21
What the best way to detect an object being attached or unattached from an avatar?
Al Bravo
Retired
Join date: 29 Jun 2004
Posts: 373
10-29-2004 10:29
attach
attach(key attached)

This event handler is invoked whenever the object is attached or detached from an avatar. If it is attached, attached is the key of the avatar it is attached to, otherwise attached == NULL_KEY.

For example:

CODE
default
{
attach(key attached)
{
if (attached != NULL_KEY) // object has been attached
{
llWhisper( 0, "I'm stuck on you, " + llKey2Name(attached) );
// etc.
}
else // object has been detached
{
llWhisper( 0, "Why hast thou forsaken me?" );
// etc.
}
}
}
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
10-29-2004 10:31
ty bravo, next time I see you in game. I"ll be sure to rate you. ^.^
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
10-29-2004 10:48
Just bear in mind that attach() goes off any time your avatar crosses a sim boundary. Don't be stupid like me and put a call to llListen() inside the attach() event. :o
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Shack Dougall
self become: Object new
Join date: 9 Aug 2004
Posts: 1,028
10-29-2004 12:37
From: Cross Lament
Just bear in mind that attach() goes off any time your avatar crosses a sim boundary. Don't be stupid like me and put a call to llListen() inside the attach() event. :o


hmmm... I'm playing with this now. and it doesn't seem to be firing when I cross a sim boundary. Could this be a bug that they fixed...or is this a new bug that they've introduced. :rolleyes:
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
10-29-2004 14:50
it would be easy to test ;)
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-30-2004 15:33
From: Cross Lament
Just bear in mind that attach() goes off any time your avatar crosses a sim boundary. Don't be stupid like me and put a call to llListen() inside the attach() event. :o


CODE
key test;
string sim;

default
{
attach(key attached)
{
key temp=llGetKey();
if (attached != NULL_KEY && test!=temp) // object has been attached
{
sim=llGetRegionName();
test=temp;
llWhisper( 0, "I'm stuck on you, " + llKey2Name(attached) );
// etc.
}
else if(attached == NULL_KEY) // object has been detached
{
llWhisper( 0, "Why hast thou forsaken me?" );
// etc.
}
else // av has crossed a sim boundry
{
string this=llGetRegionName();
llWhisper( 0, "I never liked "+sim+" anyway, so glad we are in "+this+" now.");
sim=this;
}
}
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Shack Dougall
self become: Object new
Join date: 9 Aug 2004
Posts: 1,028
10-30-2004 17:43
From: Strife Onizuka

...code to test Cross's assertion that attach() fires when you cross sim boundaries...


Honestly, guys. It just isn't happening for me. I took Strife's code. Put it in a new prim. Attached the prim to my spine. And crossed several sim boundaries around Atis. Then, detatched the prim.

All that was printed to my chat window was:

Object whispers: I'm stuck on you, Shack Dougall
Object whispers: Why hast thou forsaken me?

Did I do something wrong? It really looks like it's a bug that's been fixed to me.

Can someone tell me a sim boundary where Strife's script produces output? I'd really like to go and test it. One boundary that it doesn't work on is Atis(10,10) --> Sakai
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
10-30-2004 18:26
Well, it certainly happened to me. :D

I'd built a sort of weapon, I suppose, that was triggered by voice command. Being silly, it called llListen from the attach() event, and never actually got RID of these Listens. Eventually, I set this thing off, and it rezzed about a billion objects and promptly crashed the sim. Ooops. :o

I asked a Linden (who it was I no longer remember), and that's where I found out that crossing sim boundaries triggers attach() events. Who knows... this might've been changed/fixed since. :D
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
10-30-2004 23:11
Perhaps cretin functions trigger new threads that run in parallel to the script. Feeding the script data as it's change or created, lisson could be one of these events. If those threads are sim dependent, new thread would have to be created for each sim encountered. If creation of the new threads was automatic, but the deletion of the old threads was not. Then there would be a build up of threads.

but I know nothing about how events relation ship to sims.
Moleculor Satyr
Fireflies!
Join date: 5 Jan 2004
Posts: 2,650
10-31-2004 04:50
It's definitely been fixed since. I vaguely recall it being on one of the patch notes.

I don't remember if teleporting was fixed too or not though.
Shack Dougall
self become: Object new
Join date: 9 Aug 2004
Posts: 1,028
10-31-2004 07:39
From: Moleculor Satyr
It's definitely been fixed since. I vaguely recall it being on one of the patch notes.

I don't remember if teleporting was fixed too or not though.


It is fixed on teleports.
Shack Dougall
self become: Object new
Join date: 9 Aug 2004
Posts: 1,028
10-31-2004 08:41
From: Moleculor Satyr
It's definitely been fixed since. I vaguely recall it being on one of the patch notes.

I don't remember if teleporting was fixed too or not though.


It does fire on true teleporting, but not sit teleporting. I'm not experienced enough to know if this is a problem or not. When it attaches after a teleport, the attachment has a new key (as you would expect).

I guess the listens, etc., get wiped out on teleport and have to be reinitialized. So the attach() needs to fire in this case. But I'll do some experiments.
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
11-03-2004 00:06
this evening I spent a few hours playing around with attach(key attached){llSay(0,"attached triggered"; } This is what I experienced.


CODE
 Attach was not triggered by:
* scripted object being moved from one sim to another.
* While the object was attached, flying between sims.
* Walking between sims.
* 'teleporting scripts' witch move the avatar , not teleport the avatar. (no big surprise there)
* attached to avatar, recompiling the script
* object attached to avatar, logout
* object attached to avatar, before teleporting

Attach was triggered when:
* from ground, object was attached to avatar
* from inventory, object was attached to avatar.
* on avatar, object dropped to ground.
* on avatar, object was returned to inventory.
* after teleporting.
* on login.



Putting it in a list like that make it look simple. BUT for some reason, I have had other results. Some times I would teleport, and it did not seem to send a message. Another time I logged in, and received attach happening twice. O.o Ones it did not trigger for a full 4 minutes. I've passed those off as oddities, Because I haven't been able to recreate the anomalies.


this is the code I then developed for testing:
CODE
key user;

default
{
state_entry()
{
llSay(0, "state_entry");
}


attach(key attached)
{
if ( attached != NULL_KEY && user == attached )
{
llSay(0, "teleport or login");
}
else if ( attached != NULL_KEY )
{
user = attached;
llSay(0, "attached" );
}
else
{
user = attached;
llSay(0, "detached");
}
}
}


I don't think there is really an easy way, or a 100% perfect way to tell the difference between a login, and a teleport. Recording the location of the sim, might work, but sense changing sims dose not trigger a trigger, if an avatar attach an object in one sim, and moves to another, and then logs out. Next time they log in the code improperly recognize the login as a teleport.

I would guess there would be no difference between teleporting, or logging in. AS far as sls is concerned. But some times the lisson event stops working after a teleporting. Other times both teleporting and logging in cause problems with lisson. Some times logging in cause problem, but teleporting did not. O.o

What bother me about lisson. Depending on what trigger triggered the lesson event. The lesson may no longer be triggered , after a teleport, and or on login. (while the object attached to avatar) But there doesn't seem to be some sort of standard defect. I"m trying to imply, that a lisson triggered by state_entry, may function differently then a lisson triggered by touch, touch_start, or attach.
The only part that seemed to be standard about lissons freaking out, putting the object into inventory, and then back out seems to reactivate the lisson.

maybe tomorrow i'll do more testing. With a more strict scientific process. So I can nail down what is happening. If I'm not too bizzy packing for my trip to norther california, wine country here I come.
Some of this might be just my own user error. It is late, and I am tired.
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
11-03-2004 11:34
ok interesting side note on_rez is also triggered on login or teleport.