llGetAttached
integer llGetAttached()Returns the object's attachment point, or 0 if not attached.
Example 1: Enforce Attachment Location
Section titled “Example 1: Enforce Attachment Location”This script validates that an object is attached to the left hand, and requests detachment if attached elsewhere:
default{ attach(key id) { if(id)//it's attached { if(llGetAttached() != ATTACH_LHAND) { llOwnerSay("Please attach me only to the left hand"); llRequestPermissions(id, PERMISSION_ATTACH); } } } run_time_permissions(integer a) { if(a & PERMISSION_ATTACH) llDetachFromAvatar(); }}Example 2: Toggle Visibility Based on Attachment State
Section titled “Example 2: Toggle Visibility Based on Attachment State”This snippet makes a prim invisible when attached, but visible when rezzed unattached:
on_rez(integer p){ // !llGetAttached() has the value 0 when attached, and 1 when unattached llSetAlpha( !llGetAttached(), ALL_SIDES);}- Returns the attachment point constant (e.g.,
ATTACH_LHAND,ATTACH_HEAD) when attached - Returns
0when the object is not attached or is pending detachment - The return value can be used in boolean context:
!llGetAttached()evaluates toTRUEwhen not attached andFALSEwhen attached