Difference between revisions of "Attach"

From Second Life Wiki
Jump to: navigation, search
(explain the "looping" problem a little more fully)
Line 24: Line 24:
 
# When the avatar wearing the object moves from one region to another
 
# When the avatar wearing the object moves from one region to another
 
#* Use [[CHANGED_REGION]] to detect when the avatar changes region
 
#* Use [[CHANGED_REGION]] to detect when the avatar changes region
|caveats
+
|caveats=*When detached to inventory, an object is only given limited time to execute its attach events. If these events are active when the script derezzes but have not completed, execution will finish when the object is next rezzed. <sup>[http://forums-archive.secondlife.com/54/8b/65518/1.html#post689314]</sup> If the script is busy handling a ''different'' event at detach time, an attach event with id=NULL_KEY can happen on the next rez, followed by one with the wearer's key. To verify a real detach, check that id == NULL_KEY ''AND'' llGetAttached() == 0.
 +
* If the script is busy with a complex event handler before it is taken to inventory, the [[:Category:LSL_Events|event queue]] can overflow, leaving no room to capture new events. The queue is preserved, so attach and on_rez may not be triggered the next time the object is rezzed. To guard against this possibility, [[llGetAttached]] can be checked in other events.
 
|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.
Line 55: Line 56:
 
===[[on_rez]] & [[attach]]===
 
===[[on_rez]] & [[attach]]===
 
[[on_rez]] will be triggered prior to [[attach]] when attaching from inventory or during login.
 
[[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 your detach code simple.
 
 
If the script is busy with a complex event handler before it is taken to inventory, the [[:Category:LSL_Events|event queue]] can overflow, leaving no room to capture new events. The queue is preserved, so attach and on_rez may not be triggered the next time the object is rezzed. To guard against this possibility, [[llGetAttached]] can be checked in other events.
 
  
 
|mode
 
|mode

Revision as of 18:20, 8 April 2011

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 (does not occur with current versions, but scripters should anticipate the possibility)

Not Triggered

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

Caveats

  • When detached to inventory, an object is only given limited time to execute its attach events. If these events are active when the script derezzes but have not completed, execution will finish when the object is next rezzed. [1] If the script is busy handling a different event at detach time, an attach event with id=NULL_KEY can happen on the next rez, followed by one with the wearer's key. To verify a real detach, check that id == NULL_KEY AND llGetAttached() == 0.
  • If the script is busy with a complex event handler before it is taken to inventory, the event queue can overflow, leaving no room to capture new events. The queue is preserved, so attach and on_rez may not be triggered the next time the object is rezzed. To guard against this possibility, llGetAttached can be checked in other events.
All Issues ~ Search JIRA for related Bugs

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

on_rez & attach

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

See Also

Events

• on_rez

Functions

• llAttachToAvatar
• llDetachFromAvatar
• llGetAttached

Articles

• Attachment

Deep Notes

Signature

event void attach( key id );