Difference between revisions of "Open Prim Animator/Touch Ping Pong"

From Second Life Wiki
Jump to navigation Jump to search
(Committing changes made to OPA made over the past year at work)
 
(moar documentation)
Line 1: Line 1:
<lsl>
<lsl>
//!  @brief This is a utility script for OPA for cases when animation frames are meant to be viewed sequentially in both forward and "reverse".
/**
*    @author SignpostMarv Martin
*/
//!  The number of animation frames
integer count;
integer count;
//!  if TRUE then the "ping pong" is in effect and should not be interupted.
integer running=FALSE;
integer running=FALSE;
//!  interval between animation frames
float interval = 1.0;
float interval = 1.0;
//! 
integer at=1;
integer at=1;
integer mod=1;
integer mod=1;
default{
default{
     state_entry() {
     state_entry() {
         llMessageLinked(LINK_ROOT, -1, "XDrecordedSnapshots", NULL_KEY);
         llMessageLinked(LINK_ROOT, -1, "XDrecordedSnapshots", NULL_KEY); // get the number of animation frames from the core OPA script.
     }
     }


     link_message(integer s, integer n, string m, key i){
     link_message(integer s, integer n, string m, key i){
         if(m == "XDrecordedSnapshots" && n >= 0){
         if(m == "XDrecordedSnapshots" && n >= 0){
             count = n;
             count = n; // update the number of animation frames
         }
         }
     }
     }


     touch_start(integer t){
     touch_start(integer t){
         if(!running){
         if(!running){ // if we're not doing the "ping-pong",
             running = TRUE;
             running = TRUE; // set the flag to TRUE
             llSetTimerEvent(interval);
             llSetTimerEvent(interval); // then set the timer event away.
         }
         }
     }
     }
Line 25: Line 37:
     timer(){
     timer(){
         if(count <= 0){
         if(count <= 0){
             llSetTimerEvent(0);
             llSetTimerEvent(0); // stop the timer
         }else{
         }else{
             at += mod;
             at += mod; // add the modifier (which may be a negative integer)
             if(at >= count){
             if(at >= count){ // if we're at the end of the "ping-pong",
                 mod = -1;
                 mod = -1; // change the mod to negative 1 in preparation of reversing the animation
                 llSetTimerEvent(0);
                 llSetTimerEvent(0); // turn off the timer
                 running = FALSE;
                 running = FALSE; // set the running flag to FALSE so a user can touch the script.
             }else if(at <= 1){
             }else if(at <= 1){ // if we're at the end of the "pong-ping",
                 mod = 1;
                 mod = 1; // change them od to positive one in preparation of running the animation
                 llSetTimerEvent(0);
                 llSetTimerEvent(0); // turn off the timer.
                 running = FALSE;
                 running = FALSE; // set the running flag to FALSE so a user can touch the script.
             }
             }
             llMessageLinked(LINK_ROOT, at, "XDshow", NULL_KEY);
             llMessageLinked(LINK_ROOT, at, "XDshow", NULL_KEY); // instruct the core OPA script to change the displayed animation frame.
         }
         }
     }
     }

Revision as of 05:04, 14 December 2011

<lsl> //! @brief This is a utility script for OPA for cases when animation frames are meant to be viewed sequentially in both forward and "reverse". /**

  • @author SignpostMarv Martin
  • /

//! The number of animation frames integer count;

//! if TRUE then the "ping pong" is in effect and should not be interupted. integer running=FALSE;

//! interval between animation frames float interval = 1.0;

//! integer at=1; integer mod=1; default{

   state_entry() {
       llMessageLinked(LINK_ROOT, -1, "XDrecordedSnapshots", NULL_KEY); // get the number of animation frames from the core OPA script.
   }
   link_message(integer s, integer n, string m, key i){
       if(m == "XDrecordedSnapshots" && n >= 0){
           count = n; // update the number of animation frames
       }
   }
   touch_start(integer t){
       if(!running){ // if we're not doing the "ping-pong",
           running = TRUE; // set the flag to TRUE
           llSetTimerEvent(interval); // then set the timer event away.
       }
   }
   timer(){
       if(count <= 0){
           llSetTimerEvent(0); // stop the timer
       }else{
           at += mod; // add the modifier (which may be a negative integer)
           if(at >= count){ // if we're at the end of the "ping-pong", 
               mod = -1; // change the mod to negative 1 in preparation of reversing the animation
               llSetTimerEvent(0); // turn off the timer
               running = FALSE; // set the running flag to FALSE so a user can touch the script.
           }else if(at <= 1){ // if we're at the end of the "pong-ping",
               mod = 1; // change them od to positive one in preparation of running the animation
               llSetTimerEvent(0); // turn off the timer.
               running = FALSE; // set the running flag to FALSE so a user can touch the script.
           }
           llMessageLinked(LINK_ROOT, at, "XDshow", NULL_KEY); // instruct the core OPA script to change the displayed animation frame.
       }
   }

} </lsl>