List2ListLoop

From Second Life Wiki
Revision as of 06:43, 6 June 2009 by BETLOG Hax (talk | contribs) (New page: Tired of llList2List automatically reordering your output when your negative index comes before a positive index? eg: <lsl> list gData = ["A","B","C","D","E"]; .... llList2Li...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Tired of llList2List automatically reordering your output when your negative index comes before a positive index?

eg: <lsl> list gData = ["A","B","C","D","E"]; ....

   llList2List(gData,4, -3) = A, B, C, E // ok
   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.

</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)

<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--- //========================================================================= // //---------------------------------- 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>