Talk:LlAttachToAvatarTemp

From Second Life Wiki
Revision as of 11:22, 19 August 2012 by Innula Zenovka (Talk | contribs)

Jump to: navigation, search

Possible Caveat about need to re-request permissions to detach objects

I've just been playing with this, trying to attach and detach items by script, and I think this may be worth a caveat.

I have made an rezzer that, when touched the first time, rezzes an object that asks for PERMISSION_ATTACH and, if this is granted, attaches to you temporarily. The second time it's touched, it tells the object to detach.

If I own the rezzer, then the temp attached object detaches without needing to request PERMISSION_ATTACH a second time. It simply detaches. That's as I would expect, since there's nothing in the script to remove the permission.

However, when my alt touches it, it has to re-request PERMISSION_ATTACH or the operation silently fails. And it's the same when I gave a copy of the rezzer to my alt. Then it needs to re-request permissions when I use it.

The permissions are silently granted once it's attached, but you do seem to need to ask for them. It took me ages to realise this was why another object I was testing worked for me and no one else.

My two scripts are <lsl> key av; integer toggle; integer avnumber;

/*user function by Kira Komarov http://wiki.secondlife.com/wiki/Key2Number*/ integer Key2Number(key objKey) {

   return ((integer)("0x"+llGetSubString((string)objKey,-8,-1)) & 0x3FFFFFFF) ^ 0x3FFFFFFF;

}


default {

   state_entry()
   {
   }
   touch_start(integer total_number)
   {
       toggle=!toggle;
       if(toggle){
           av = llDetectedKey(0);
           avnumber = Key2Number(av);
           llRezAtRoot(llGetInventoryName(INVENTORY_OBJECT,0),llGetPos()+<0.0,0.0,1.0>,ZERO_VECTOR,llGetRot(),avnumber);
       }
       else{
           llRegionSayTo(av,avnumber,"detach");
       }
   }

} </lsl> and <lsl> integer Key2Number(key objKey) { /*user function by Kira Komarov http://wiki.secondlife.com/wiki/Key2Number */

   return ((integer)("0x"+llGetSubString((string)objKey,-8,-1)) & 0x3FFFFFFF) ^ 0x3FFFFFFF;

} integer avnumber; default {

   on_rez(integer start_param)
   {
       if(start_param){
           llSetPrimitiveParams([PRIM_TEMP_ON_REZ,TRUE]);
           avnumber = start_param;
           llSensor("","",AGENT,20.0,PI);
       }
   }
   sensor(integer total_number)
   {
       integer i;
       while(i<total_number){
           key k = llDetectedKey(i);
           if(Key2Number(k)==avnumber){
               llRequestPermissions(k,PERMISSION_ATTACH);
               return;
           }
           i++;
       }
   }
   run_time_permissions(integer permissions)
   {
       if(permissions & PERMISSION_ATTACH){
           if(llGetAttached()){
               llDetachFromAvatar();
           }
           else{
               llAttachToAvatarTemp(ATTACH_LHAND);
           }
       }
   }
   listen(integer channel, string name, key id, string message)
   {
       if(llGetAttached()){
           if(llGetPermissions()&PERMISSION_ATTACH){
               llOwnerSay("got permissions -- don't need to ask for them again");
               llDetachFromAvatar();
           }
           else{
               llOwnerSay("haven't got permissions -- asking for them again");
               llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
           }
       }
   }
   attach(key attached)
   {
       if(attached){
           llListen(avnumber,"","","detach");
       }
   }

} </lsl>

Innula Zenovka 11:22, 19 August 2012 (PDT)