Difference between revisions of "User:ANSI Soderstrom/Event Scanner CHANGED"

From Second Life Wiki
Jump to navigation Jump to search
 
Line 43: Line 43:
// functions section
// functions section
// ----------------------------------------------
// ----------------------------------------------
integer shift(integer bit) {
    // shift bitwise
    return 1 << bit;
}


integer reset(list todo) {
integer reset(list todo) {
Line 60: Line 55:
integer found(list changelist, integer stride, integer trigger) {
integer found(list changelist, integer stride, integer trigger) {
     integer i;
     integer i;
   
     // go backwards throught the trigger list...
     // go backwards throught the trigger list...
     for(i=(llGetListLength(changelist)/stride)-1;~i;--i) {
     for(i=(llGetListLength(changelist)/stride)-1;~i;--i) {
       
         // ...while the whole trigger > 0...
         // ...while the whole trigger > 0...
         if((trigger-shift(i)) >=0) {
         if(llList2Integer(changelist,i*2) <= trigger) {
           
             // ...and put the last posible single-trigger to a list...
             // ...and put the last posible single-trigger to a list...
             VALUE += [  llList2String(changelist,(stride*2)+1),
             VALUE += [  llList2String(changelist,i*2+1),
                         llList2String(changelist,stride)
                         llList2String(changelist,i*2)
                     ];
                     ];
             // and finally decrease the whole trigger with the stored single-trigger :)
             // and finally decrease the whole trigger with the stored single-trigger :)
             trigger = trigger - shift(i);
             trigger = trigger - llList2Integer(changelist,i*2);
         }
         }
     }     
     }     

Latest revision as of 08:46, 3 February 2011

Leave a comment

Eventscanner: changed()

Find out what is really changing... Attached or loose...

<lsl> // (C) ANSI Soderstrom 02.02.2011

// This Script detects all possible change-events // // About this coding-style: // BIGLETTERS: are ever global variables // smallletters: are ever local variables

// ---------------------------------------------- // global variables section // ----------------------------------------------

// the list with the event-triggers list TRIGGER = [ CHANGED_INVENTORY, "CHANGED_INVENTORY",

                CHANGED_COLOR,        "CHANGED_COLOR",
                CHANGED_SHAPE,        "CHANGED_SHAPE",
                CHANGED_SCALE,        "CHANGED_SCALE",
                CHANGED_TEXTURE,      "CHANGED_TEXTURE",
                CHANGED_LINK,         "CHANGED_LINK",
                CHANGED_ALLOWED_DROP, "CHANGED_ALLOWED_DROP",
                CHANGED_OWNER,        "CHANGED_OWNER",
                CHANGED_REGION,       "CHANGED_REGION",
                CHANGED_TELEPORT,     "CHANGED_TELEPORT",
                CHANGED_REGION_START, "CHANGED_REGION_START",
                CHANGED_MEDIA,        "CHANGED_MEDIA"
              ];
              

// a list to build a returnvalue (messagelinked) list VALUE = [];

// strides ??? wtf does this means ? list VALUE_DESC = ["CONSTANT_NAME","VALUE"];

// ---------------------------------------------- // functions section // ----------------------------------------------

integer reset(list todo) {

   // reset VALUE useful ?
   if(todo!=[]) {
       VALUE = [];   
       return 1;
   }
   return 0;

}

integer found(list changelist, integer stride, integer trigger) {

   integer i;
   
   // go backwards throught the trigger list...
   for(i=(llGetListLength(changelist)/stride)-1;~i;--i) {
       
       // ...while the whole trigger > 0...
       if(llList2Integer(changelist,i*2) <= trigger) {
           
           // ...and put the last posible single-trigger to a list...
           VALUE += [  llList2String(changelist,i*2+1),
                       llList2String(changelist,i*2)
                    ];
           // and finally decrease the whole trigger with the stored single-trigger :)
           trigger = trigger - llList2Integer(changelist,i*2);
       }
   }    
   return 1;

}

// ---------------------------------------------- // states section // ----------------------------------------------

default {

   state_entry() {
       
       // be verbose (Channel 1)
       llMessageLinked(LINK_THIS,1,llList2CSV(llParseString2List(llGetScriptName(),["."],[""])),NULL_KEY);
        
   }
          
   changed(integer change) {
   
       // what is happened ???
       if(found(TRIGGER,llGetListLength(VALUE_DESC),change)) {
           
           // Send all events to the parser (Channel 0)
           llMessageLinked(LINK_THIS,0,llList2CSV(llParseString2List(llGetScriptName(),["."],[""]) + [llGetListLength(VALUE_DESC)] + VALUE_DESC + VALUE),NULL_KEY);
           
       }
       
       // forget all
       if(reset(VALUE)) {
           
           // just a joke ;)
           return;   
           
       } 
   } 
       

}

</lsl>