List2ListLoop

From Second Life Wiki
Revision as of 06:01, 6 June 2009 by BETLOG Hax (talk | contribs)
Jump to navigation Jump to search

Tired of llList2List automatically reordering your output?

eg: <lsl> list gData = ["A","B","C","D","E"]; // indexes 0, 1, 2, 3, 4 // negative indexes -5, -4, -3, -2, -1 ....

   llList2List(gData,4, -3) = A, B, C, E // not really intuitive, output is automatically rearranged, and is thereby NOT what was requested.

// what I really wanted was E, A, B, C // or possibly E, D, C

   llList2List(gData,3, -2) = D // ok
   llList2List(gData,2, -1) = C, D, E // ok
   llList2List(gData,1, 4) = B, C, D, E // ok
   llList2List(gData,0, 3) = A, B, C, D // ok
   llList2List(gData,-1, 2) = A, B, C, E // not really intuitive, output is automatically rearranged, and is thereby NOT what was requested.

// what I really wanted was E, A, B, C // or possibly E, D, C </lsl> This sucks in situations where you want your data in a circular loop. (or when you expect llList2List to actually give you what you asked for), and can be particularly problematic when attempting to extract a small window of data, and suddenly a LARGE window of data is returned..in the wrong sequence. <lsl> //========================================================================= // BETLOG Hax // Efficiency modifications by Nomad Padar // 20090606 //========================================================================= // ---LICENCE START--- // http://creativecommons.org/licenses/by-sa/3.0/ // http://creativecommons.org/licenses/LGPL/2.1/ // ie: Attribution licence: // Give me credit by leaving it in the script I created. // And/Or supply my original script with your modified version. // ---LICENCE END--- //========================================================================= //

//NOTE: gCount = (gData!=[]); //the length of the main list, not the window being extracted //ie: //gCount = llGetlistLength(gData);

//---------------------------------- list f_list2ListLoop(list data, integer begin, integer end)//less legible, same thing { if ((end=(end+gCount)%gCount)<(begin=(begin+gCount)%gCount))

       return llList2List(data, begin,-1)+llList2List(data, 0, end);
   return llList2List(data, begin, end);

} //---------------------------------- list f_list2ListLoop(list data, integer begin, integer end)//more legible, same thing { begin = (begin+gCount)%gCount;

   end = (end+gCount)%gCount;
   if (end<begin)
       return llList2List(data, begin,-1)+llList2List(data, 0, end);
   return llList2List(data, begin, end);

} //---------------------------------- </lsl>