Difference between revisions of "User talk:Chibbchichi Resident"

From Second Life Wiki
Jump to navigation Jump to search
Line 23: Line 23:
</lsl>   
</lsl>   


 
 
<lsl>
<lsl>
// A simple typing override example.
// A simple typing override example.
Line 29: Line 29:
// Also included an easy way to hide and show the whole object depending on current typing state.
// Also included an easy way to hide and show the whole object depending on current typing state.
// For example: Show a keyboard under avatars hands when avatar types.
// For example: Show a keyboard under avatars hands when avatar types.
// User functions
doStuff(){
    llStartAnimation("run");
    llSetAlpha(1,ALL_SIDES);
}
stopStuff(){
    llStopAnimation("run");
    llSetAlpha(0,ALL_SIDES);
}


key gOwner; // the wearer's key
key gOwner; // the wearer's key
integer gLastAnimation; // last llGetAnimation value seen
integer gWasTyping; // last state of typing seen
// Event handlers
default
{
    state_entry() {
        string id=llGetOwner();
        // in case the script was reset while already attached
        if (llGetAttached() != 0) {
            if (id == NULL_KEY) { // detaching
                llSetTimerEvent(0.0); // stop the timer
            }
            else { // attached, or reset while worn
                llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
                gOwner = id;
            }
        }
    }
    attach(key id) {
        llResetScript();
    }
    run_time_permissions(integer perm) {
        if (perm & PERMISSION_TRIGGER_ANIMATION) {
            llSetTimerEvent(0.25); // start polling
        }
    }
    timer() {
        integer newAnimation = llGetAgentInfo(gOwner);
        if (gLastAnimation != newAnimation) { // any change?
            if(newAnimation & AGENT_TYPING){
                doStuff();
            }
            else if (gLastAnimation !=(newAnimation & AGENT_TYPING))  {
                stopStuff();
            }
            gLastAnimation = newAnimation; // store away for  next time
        }
    }
}
</lsl>
 
 
[V2]
<lsl>
// A simple typing override example.
// Modified the example-LSL of llGetAnimation to make it work with llGetAgentInfo.
// Also included an easy way to hide and show the whole object depending on current typing state.
// For example: Show a keyboard under avatars hands when avatar types.
key gOwner; // the wearer's key
integer gLastAnimation; // last llGetAnimation value seen
   
   
// User functions
// User functions
doStuff(){
    llStartAnimation("run");
    llSetAlpha(1,ALL_SIDES);
}
stopStuff(){
    llStopAnimation("run");
    llSetAlpha(0,ALL_SIDES);
}
Initialize(key id){
Initialize(key id){
     // in case the script was reset while already attached
     // in case the script was reset while already attached
Line 140: Line 65:
   
   
     timer() {
     timer() {
         integer newAnimation = llGetAgentInfo(gOwner);
         integer typingNow = llGetAgentInfo(llGetOwner()) & AGENT_TYPING;
        integer isTyping = newAnimation & AGENT_TYPING;
   
   
         if (gLastAnimation != newAnimation) { // any change?
         if (gWasTyping != typingNow) { // any change?
             if(isTyping){
             if(typingNow){ // set whole object visible when typing
                 doStuff();
                llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
                 llMessageLinked( LINK_SET,1,"","");
             }
             }
             else if (gLastAnimation != isTyping) {
             else{ // set whole object invisible if not typing
                 stopStuff();
                llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES);
                 llMessageLinked( LINK_SET,0,"","");
             }
             }
             gLastAnimation = newAnimation; // store away for  next time
             gWasTyping = typingNow; // store away for  next time
         }
         }
     }
     }
   
  /* touch_start(integer a){
        llOwnerSay((string)llDetectedLinkNumber(0));
        llOwnerSay((string)llDetectedTouchFace(0));
    }*/
}
}
</lsl>
</lsl>

Revision as of 09:42, 29 December 2013

llGetAgentInfo Example

I saw your recent contribution to llGetAgentInfo, but I felt it had some problems that needed addressing, so I took the liberty of moving it to here. Your attach event resets the script, forcing it back through state_entry. Within state_entry you assign the owner's key to the string 'id' (strictly should be a key variable). But then you attempt to test if the object is being detached by checking if id is NULL_KEY - but it can't be. That test needs to be done inside the attach() event. Stopping the timer from within state_entry is pointless, as no timer will be running first time nor on script reset. Within timer(), the information you gain from llGetAgentInfo() is not only about whether the agent is typing. It could for example include mouselook indication, or if they are flying. So testing this data for a change in typing status is not totally valid. You must isolate the AGENT_TYPING bit straightaway. I won't try and fix the whole script, but perhaps this would work for the timer code. The rest needs a bit of a rethink. Omei Qunhua 11:18, 26 December 2013 (PST)

<lsl> timer() {

   integer TypingNow = llGetAgentInfo( llGetOwner() ) & AGENT_TYPING;
   if (TypingNow != gLastAnimation)
   {
        if (TypingNow)
           doStuff();
        else
           stopStuff();
       gLastAnimation = TypingNow;
   }  

} </lsl>


<lsl> // A simple typing override example. // Modified the example-LSL of llGetAnimation to make it work with llGetAgentInfo. // Also included an easy way to hide and show the whole object depending on current typing state. // For example: Show a keyboard under avatars hands when avatar types.

key gOwner; // the wearer's key integer gWasTyping; // last state of typing seen

// User functions Initialize(key id){

   // in case the script was reset while already attached
   if (llGetAttached() != 0) {
       if (id == NULL_KEY) { // detaching
           llSetTimerEvent(0.0); // stop the timer
       }
       else { // attached, or reset while worn
           llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
           gOwner = id;
       }
   }

}

// Event handlers default {

   state_entry() {
       Initialize(llGetOwner());
   }

   attach(key id) {
       Initialize(id);
   }

   run_time_permissions(integer perm) {
       if (perm & PERMISSION_TRIGGER_ANIMATION) {
           llSetTimerEvent(0.25); // start polling
       }
   }

   timer() {
       integer typingNow = llGetAgentInfo(llGetOwner()) & AGENT_TYPING;

       if (gWasTyping != typingNow) { // any change?
           if(typingNow){ // set whole object visible when typing
               llSetLinkAlpha(LINK_SET, 1.0, ALL_SIDES);
               llMessageLinked( LINK_SET,1,"","");
           }
           else{ // set whole object invisible if not typing
               llSetLinkAlpha(LINK_SET, 0.0, ALL_SIDES);
               llMessageLinked( LINK_SET,0,"","");
           }
           gWasTyping = typingNow; // store away for  next time
       }
   }
   
  /* touch_start(integer a){
       llOwnerSay((string)llDetectedLinkNumber(0));
       llOwnerSay((string)llDetectedTouchFace(0));
   }*/

} </lsl>