Don't click here unless you want to be banned.

LSL Wiki : attach

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawling22.us.archive.org
attach(key id)

This event handler is triggered whenever the object is attached (which makes it an attachment) or detached from the avatar. If it is attached, id contains the key of the avatar it is attached to, otherwise id contains NULL_KEY.

Example:
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.
        }
    }
}

Note: if both on_rez and attach are used, on_rez will always be triggered first.

Note: when the object is detached to inventory, it will be given a limited amount of CPU cycles to run its attach event before it is derezed. There is no guarantee that all of the code within the attach event will complete before the derez occurs. In particular, expensive operations such as llSetPos may cause the script to be descheduled early, preventing timely execution of subsequent code.

Does not fire in child prims, only in root of linked objects.

Use the llAttachToAvatar, llDetachFromAvatar and llGetAttached functions to play with attachments.


Events | Agent/Avatar | Attachment
Comments [Hide comments/form]
It seems, from my tests, that the amount of CPU cycles given to run events on detachment is OBJECT-based, rather than per-script; if you put many scripts into a single object, the attach event might not trigger at all, even if it's something as simple as a single llOwnerSay. Stranger yet, once attached, the event MAY fire (sometimes), as if it were a regular attach event (even though the key parameter in attach had to be NULL_KEY in order for the event to fire...). In other words, the attach event started to trigger on detach, though the actual execution of code did not occur until the item was reattached. This is in 1.7.
-- ZodiakosAbsolute (2005-11-08 19:08:48)
The attach event is triggered on attached or detached. While the object is attached the event is also triggered by: teleporting, log-in or log-out.
-- KurtZidane (2005-12-19 16:43:42)
note: about the attach event being triggered by teleporting; The event is triggered after teleporting into the new sim. Not leaving the old sim.
-- KurtZidane (2005-12-19 17:12:06)
I've done some recent testing (as of 1.12.0 (15)), and it doesn't look like attach() is triggered at all during logout. Either that, or logout occurs too fast now for the event to process.
-- CrossLament (2006-08-26 19:30:30)
too bad, that if you "drop" an attached temporary object which you held more than 1 minutes, it wont trigger the attach event while detaching, it dies instantly :(
-- catv-59856cb9.catv.broadband.hu (2007-09-16 14:03:41)
Attach a comment to this page: