Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llList2ListStrided - The bug and a workaound

Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
07-14-2004 16:36
Hello everyone. Yesterday night when adding features to a parser, I ran into an llList2ListStrided problem, here's the code I was using:

CODE

integer GET_CATEGORY = 302;
integer SET_CATEGORY = 303;

list CONSTANTS_AND_NAMES = [
// Constant //Name
GET_CATEGORY, "GET_CATEGORY",
SET_CATEGORY, "SET_CATEGORY"
//etc...
];

default {
state_entry() {
list constantNames = llList2ListStrided(CONSTANTS_AND_NAMES, 1, -1, 2);
integer i;
integer len = llGetListLength(constantNames);
for(i = 0; i < len; i++) {
llSay(0, llList2String(constantNames, i));
}
}
}


I kept attempting to extract only the string names in the CONSTANTS_AND_NAMES list but couldn't figure out why llList2ListStrided was only giving me the integer constants no matter what parameters I passed to it.

I IM'med ThinkTank (a scripting group) about it, and Francis Chung responded with the solution:

list fix = llList2List(CONSTANTS_AND_NAMES, 1, -1);
list constantNames = llList2ListStrided(fix, 0, -1, 2)

It seemed that llList2ListStrided was ignoring the start parameter passed to it. Francis' fix for my problem gave me the idea behind this generalized fix for llList2ListStrided:
CODE

list list2ListStrided(list src, integer start, integer end, integer stride) {
return llList2ListStrided(llList2List(src, start, end), 0, end, stride);
}

Basically, since llList2ListStrided is (currently) ignoring the start parameter, this function shifts src so that llList2ListStrided will work striding from element 0.

Even if llList2ListStrided is fixed, this function will continue to work.

==Chris
Ama Omega
Lost Wanderer
Join date: 11 Dec 2002
Posts: 1,770
07-14-2004 19:22
I think it probably doesn't ignore the start parameter.

llList2ListStrided(source, start, end, stride);

This will return a list that is every nth element of source from start to end.

So.

llList2ListStrided([0,1,2,3,4,5,6],0,-1,2);

returns: [0,2,4,6]

llList2ListStrided([0,1,2,3,4,5,6],1,-1,2);

returns: [2,4,6];

llList2ListStrided([0,1,2,3,4,5,6],2,-1,2);

returns: [2,4,6];

etc.

Do I think this is the way it should work? No. I can't off the top of my head see a use for it without first chopping off the begining of the list to select the element you really want. But I do think this is how it works.
_____________________
--
010000010110110101100001001000000100111101101101011001010110011101100001
--
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
07-14-2004 22:22
Yikes!
Heh, I should start being a little less eager to jump at the chance of reporting a bug here. Well, at least the function is useful. :D