From Second Life Wiki
Template:Needs Translation/LSL/de
Template:Needs Translation/LSL/es
Template:Needs Translation/LSL/el
Template:Needs Translation/LSL/he
Template:Needs Translation/LSL/it
Template:Needs Translation/LSL/ko
Template:Needs Translation/LSL/nl
Template:Needs Translation/LSL/hu
Template:Needs Translation/LSL/no
Template:Needs Translation/LSL/da
Template:Needs Translation/LSL/sv
Template:Needs Translation/LSL/tr
Template:Needs Translation/LSL/pt
Template:Needs Translation/LSL/ru
Template:Needs Translation/LSL/uk
Template:Needs Translation/LSL/zh-Hans
Template:Needs Translation/LSL/zh-Hant
/LSL
attach
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
- 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 == 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
- When the avatar wearing the object moves from one region to another
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.
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!");
}
}
}
Notes
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.
Also attach will not be triggered if the script was looping when last rezzed. (same with on_rez)
See Also
Events
Functions
Articles