A B C D E F G I J K L M N O R S T U V W

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 detached
        {
            llWhisper( 0, "Why hast thou forsaken me?" );
            // etc.
        }
        else   // object has been //attached//
        {
            llWhisper( 0, "I'm stuck on you, " + llKey2Name(attached) );
            // 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 llAttachToAvatarllDetachFromAvatar and llGetAttached functions to play with attachments.