Difference between revisions of "List2ListLoop"

From Second Life Wiki
Jump to navigation Jump to search
m
m (<lsl> tag to <source>)
 
Line 2: Line 2:


eg:
eg:
<lsl>
<source lang="lsl2">
list    gData      = ["A","B","C","D","E"];
list    gData      = ["A","B","C","D","E"];
//  indexes            0,  1,  2,  3,  4
//  indexes            0,  1,  2,  3,  4
Line 19: Line 19:
                                           // what I really wanted was E, A, B, C
                                           // what I really wanted was E, A, B, C
                                           // or possibly E, D, C
                                           // or possibly E, D, C
</lsl>
</source>
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),
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.
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>
<source lang="lsl2">
//=========================================================================
//=========================================================================
// BETLOG Hax
// BETLOG Hax
Line 59: Line 59:
}
}
//----------------------------------
//----------------------------------
</lsl>
</source>


you would invoke the above something like:
you would invoke the above something like:
<lsl>
<source lang="lsl2">
list window = f_list2ListLoop(gData,gIndex-2, gIndex+2);
list window = f_list2ListLoop(gData,gIndex-2, gIndex+2);
//where gIndex is an integer pointer to a position in list:gData and you want to get  
//where gIndex is an integer pointer to a position in list:gData and you want to get  
//the index position plus two entries on either side of it.
//the index position plus two entries on either side of it.
//
//
</lsl>
</source>
[[Category:LSL Examples]]
[[Category:LSL Examples]]

Latest revision as of 15:30, 24 January 2015

Tired of llList2List automatically reordering your output?

eg:

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

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.

//=========================================================================
// BETLOG Hax
// Efficiency modifications by Nomad Padar
// 20090606 
//=========================================================================
// ---LICENCE START---
// http://creativecommons.org/licenses/by-sa/3.0/
// ie: Attribution licence:
//   Give me credit by leaving it in the script I created.
//   Supply my original script with your modified version.
//   Refer to the wiki URL from which you copied this script.
//      https://wiki.secondlife.com/wiki/List2ListLoop
// ---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);
}
//----------------------------------

you would invoke the above something like:

list window = f_list2ListLoop(gData,gIndex-2, gIndex+2);
//where gIndex is an integer pointer to a position in list:gData and you want to get 
//the index position plus two entries on either side of it.
//