Difference between revisions of "Attach"

From Second Life Wiki
Jump to navigation Jump to search
(child prims)
m
Line 8: Line 8:
|event_desc=Triggered in an object when the object [[attachment|attaches]] or detaches from agent.
|event_desc=Triggered in an object when the object [[attachment|attaches]] or detaches from agent.
|constants
|constants
|spec
|spec=
===Triggered===
# When the object is attached to an avatar
#* From the ground
#* From inventory
#* When the avatar wearing the object logs in
# When object is detached ('''id''' == {{LSL_Constant/NULL_KEY}})
#* Dropped to the ground
#* Derezzed to inventory
#* When the avatar wearing the object logs out
 
===Not Triggered===
# When the avatar wearing the object teleports
#* Use [[CHANGED_TELEPORT]] to detect when the avatar teleports
# When the avatar wearing the object moves from one region to another
#* Use [[CHANGED_REGION]] to detect when the avatar changes region
|caveats
|caveats
|examples=
|examples=
The following is a simplified example of the attach event. The variable id will be the key of the avatar the scripted object is attached to otherwise it will take on the value of {{LSL_Constant/NULL_KEY}}. The conditional [[if]] statement is used to determine the value of the variable id.
The following is a simplified example of the attach event. The variable id will be the key of the avatar the scripted object is attached to otherwise it will take on the value of {{LSL_Constant/NULL_KEY}}. The conditional [[if]] statement is used to determine the value of the variable id.
<lsl>default
<lsl>default
{   
{   
Line 29: Line 43:
|helpers
|helpers
|also_header
|also_header
|also_events
|also_events=
{{LSL DefineRow|[[on_rez]]}}
|also_functions=
|also_functions=
{{LSL DefineRow|[[llAttachToAvatar]]}}
{{LSL DefineRow|[[llAttachToAvatar]]}}
Line 37: Line 52:
{{LSL DefineRow|{{LSLGC|Attachment}}}}
{{LSL DefineRow|{{LSLGC|Attachment}}}}
|also_footer
|also_footer
|notes=In child prims the attach(NULL_KEY) event is only executed directly if the object is dropped into the world. It is not executed on normal detaching but delayed until the object is attached again.
|notes=
===[[attach]] & [[on_rez]]===
[[on_rez]] will be triggered prior to [[attach]] when attaching from inventory or during login.
 
===Derez Timing===
Durring derez, an object is only given so much time to execute it's attach events. If these events are active when the script derezzes but have not completed, execution will finish when the object is next rezzed (this may not be desirable). It is advisable to keep you detach code simple.
|mode
|mode
|deprecated
|deprecated

Revision as of 21:46, 15 April 2009

Description

Event: attach( key id ){ ; }

Triggered in an object when the object attaches or detaches from agent.

• key id the avatar if attached, if not attached NULL_KEY.

Specification

Triggered

  1. When the object is attached to an avatar
    • From the ground
    • From inventory
    • When the avatar wearing the object logs in
  2. When object is detached (id == NULL_KEY)
    • Dropped to the ground
    • Derezzed to inventory
    • When the avatar wearing the object logs out

Not Triggered

  1. When the avatar wearing the object teleports
  2. When the avatar wearing the object moves from one region to another

Caveats


Examples

The following is a simplified example of the attach event. The variable id will be the key of the avatar the scripted object is attached to otherwise it will take on the value of NULL_KEY. The conditional if statement is used to determine the value of the variable id. <lsl>default {

   attach(key id)
   {
       if(id)//tests if it is a valid key and not NULL_KEY
       {
           llSay(PUBLIC_CHANNEL,"I have been attached!");
       }
       else
       {
           llSay(PUBLIC_CHANNEL,"I have been detached!");
       }
   }

}</lsl>

Notes

attach & on_rez

on_rez will be triggered prior to attach when attaching from inventory or during login.

Derez Timing

Durring derez, an object is only given so much time to execute it's attach events. If these events are active when the script derezzes but have not completed, execution will finish when the object is next rezzed (this may not be desirable). It is advisable to keep you detach code simple.

See Also

Events

• on_rez

Functions

• llAttachToAvatar
• llDetachFromAvatar
• llGetAttached

Articles

• Attachment

Deep Notes

Signature

event void attach( key id );