Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Strided List2String?

Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
08-06-2009 17:28
so i'm having some difficulty understanding something, i have a list, and i want the script to say every 2 elements. this is the results i get with my tests

first try

CODE

list stuff = ["one",1,"two",2,"three",3,"four",4,"five",5,"six",6,"seven",7,"eight",8,"nine",9,"ten",10,"eleven",11,"twelve",12,"thirteen",13,"fourteen",14];
default
{
state_entry()
{
integer len = llGetListLength(stuff);
integer i = 0;
for(i;i < len;++i)
{
string temp = llList2String(stuff,i) + " " + llList2String(stuff,++i);
llOwnerSay(temp);
}
}
}


returns:
[17:15] Object: 1 1
[17:15] Object: 2 2
[17:15] Object: 3 3
[17:15] Object: 4 4
[17:15] Object: 5 5
[17:15] Object: 6 6
[17:15] Object: 7 7
[17:15] Object: 8 8
[17:15] Object: 9 9
[17:15] Object: 10 10
[17:15] Object: 11 11
[17:15] Object: 12 12
[17:15] Object: 13 13
[17:15] Object: 14 14

second try:

CODE

list stuff = ["one",1,"two",2,"three",3,"four",4,"five",5,"six",6,"seven",7,"eight",8,"nine",9,"ten",10,"eleven",11,"twelve",12,"thirteen",13,"fourteen",14];
default
{
state_entry()
{
integer len = llGetListLength(stuff);
integer i = 0;
for(i;i < len;i++)//reversed the increment command in both
{
string temp = llList2String(stuff,i) + " " + llList2String(stuff,i++);//here
llOwnerSay(temp);
}
}
}


returns: backwards??.

[17:18] Object: 1 one
[17:18] Object: 2 two
[17:18] Object: 3 three
[17:18] Object: 4 four
[17:18] Object: 5 five
[17:18] Object: 6 six
[17:18] Object: 7 seven
[17:18] Object: 8 eight
[17:18] Object: 9 nine
[17:18] Object: 10 ten
[17:18] Object: 11 eleven
[17:18] Object: 12 twelve
[17:18] Object: 13 thirteen
[17:18] Object: 14 fourteen

third try:
CODE

list stuff = ["one",1,"two",2,"three",3,"four",4,"five",5,"six",6,"seven",7,"eight",8,"nine",9,"ten",10,"eleven",11,"twelve",12,"thirteen",13,"fourteen",14];
default
{
state_entry()
{
integer len = llGetListLength(stuff);
integer i = 0;
for(i;i < len;i++)//increment opposite from each other in the 2 places used
{
string temp = llList2String(stuff,i) + " " + llList2String(stuff,++i);//here
llOwnerSay(temp);
}
}
}


same results as the 1st try

fourth try:
CODE

list stuff = ["one",1,"two",2,"three",3,"four",4,"five",5,"six",6,"seven",7,"eight",8,"nine",9,"ten",10,"eleven",11,"twelve",12,"thirteen",13,"fourteen",14];
default
{
state_entry()
{
integer len = llGetListLength(stuff);
integer i = 0;
for(i;i < len;++i)//flipped the 2
{
string temp = llList2String(stuff,i) + " " + llList2String(stuff,i++);//here
llOwnerSay(temp);
}
}
}

same results as the second try??

the 5th try seems to do what i want, but i wonder if there's a more effeciant way of doing it?
CODE

list stuff = ["one",1,"two",2,"three",3,"four",4,"five",5,"six",6,"seven",7,"eight",8,"nine",9,"ten",10,"eleven",11,"twelve",12,"thirteen",13,"fourteen",14];
default
{
state_entry()
{
integer len = llGetListLength(stuff);
integer i = 0;
for(i;i < len;++i)
{
string temp = llList2String(stuff,i) + " " + llList2String(stuff,i + 1);//just used i + 1 instead of incrementing within the function
llOwnerSay(temp);
++i;//moved the second increment down here
}
}
}


returns:
[17:24] Object: one 1
[17:24] Object: two 2
[17:24] Object: three 3
[17:24] Object: four 4
[17:24] Object: five 5
[17:24] Object: six 6
[17:24] Object: seven 7
[17:24] Object: eight 8
[17:24] Object: nine 9
[17:24] Object: ten 10
[17:24] Object: eleven 11
[17:24] Object: twelve 12
[17:24] Object: thirteen 13
[17:24] Object: fourteen 14
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
08-06-2009 18:04
Since you're experimenting, have you tried

CODE

for(i;i < len;i++)
{
string temp = llList2String(stuff,++i) + " " + llList2String(stuff,i );//Like #2 but reversing the order in this statement
llOwnerSay(temp);
}
}


?
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
08-06-2009 18:15
in the 5th example do this:
CODE

for(i;i < len;i+=2)
{
string temp = llList2String(stuff,i) + " " + llList2String(stuff,i + 1);
llOwnerSay(temp);
}
_____________________
From Studio Dora
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
08-06-2009 21:08
These are very, very, very bad problems as this is not the way pre or post increment are supposed to work. Your first or second examples should have worked fine. Seems to be a serious problem somewhere tonight because look at the return from this script:

CODE

list stuff =
["one", 1, "two", 2, "three", 3, "four", 4, "five", 5, "six", 6, "seven", 7, "eight", 8, "nine", 9, "ten", 10,
"eleven", 11, "twelve", 12, "thirteen", 13, "fourteen", 14];
default {
state_entry() {
integer len = llGetListLength(stuff);
integer i;
while (i < len) {
llOwnerSay(llList2String(stuff, i));
llOwnerSay(llList2String(stuff, ++i));
++i;
}
}
}

21:04] Object: one
[21:04] Object: 1
[21:04] Object: two
[21:04] Object: 2
[21:04] Object: 3
[21:04] Object: four
[21:04] Object: three
[21:04] Object: five
[21:04] Object: 4
[21:04] Object: 5
[21:04] Object: six
[21:04] Object: 6
[21:04] Object: seven
[21:04] Object: 7
[21:04] Object: eight
[21:04] Object: 8
[21:04] Object: nine
[21:04] Object: 9
[21:04] Object: ten
[21:04] Object: 10
[21:04] Object: eleven
[21:04] Object: 11
[21:04] Object: twelve
[21:04] Object: 12
[21:04] Object: 13
[21:04] Object: fourteen
[21:04] Object: 14
[21:04] Object: thirteen
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
08-06-2009 21:18
yeah that is odd lol. when reading from a notecard in another script, i increment it within the function and it worked fine

query = llGetNotecardLine(notename, ++i);

now i did have to switch it to pre-increment, because using post increment, seemed to make it begin and end weird, it would always read the first line twice, and it wasn't supposed to do anything with EOF, but it would always dump an empty string after the last line
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
08-06-2009 21:21
Seems to be just server related and not actually a MONO problem. The packages just are not being delivered to the client in the correct order. I know that the wiki is all screwed up tonight
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
08-07-2009 01:21
@Jesse:
chat to viewer on very fast ownerSays isn't always in the fed order (I think there's a queuing difference in the viewer)... scripts will receive correct order though.


@Ruthven
CODE

integer vIntCnt = ~-([] != gLstStrided);
//-- same as (-llGetListLength( gLstStrided ) - 1)

while (++vIntCnt){
llOwnerSay( llDumpList2String( llList2List( gLstStrided, vIntCnt, ++vIntCnt ), ", " ) );
}
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
08-07-2009 02:31
From: Void Singer
@Jesse:
chat to viewer on very fast ownerSays isn't always in the fed order (I think there's a queuing difference in the viewer)... scripts will receive correct order though.


@Ruthven
CODE

integer vIntCnt = ~-([] != gLstStrided);
//-- same as (-llGetListLength( gLstStrided ) - 1)

while (++vIntCnt){
llOwnerSay( llDumpList2String( llList2List( gLstStrided, vIntCnt, ++vIntCnt ), ", " ) );
}

That's the problem! The script is not receiving it in correct order. Look at his first two examples again, one should come first, not 1.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-07-2009 03:35
The original problem was that the order of evaluation in LSL is not obvious. It's far safer to avoid using operations with side effects if you're using the same variable more than once in the expression. As it turns out, LL decided to actually define the order of operations in LSL, because people were writing code that depended on this... but the resulting code is still hard to understand.

In the expression, use "...llList2String(l,i) + llList2String(l,i+1)...;"

Then, increment the variable by the stride: "i += 2;"
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
08-07-2009 04:56
From: Jesse Barnett
That's the problem! The script is not receiving it in correct order. Look at his first two examples again, one should come first, not 1.

my comment to you was re your script showing out of order chat, in OP's post it fell victim to order of operations....

order of operations in lsl is right to left, but for function parameters it left to right (and then right to left within the parameter, which can get even messier with functions that take lists as parameters)

eg
integer vIntCnt;
llOwnerSay( (string)(++vIntCnt) + (string)(++vIntCnt) + (string)(++vIntCnt) + (string)(++vIntCnt) + );

will yield "4321" (right to left evaluation of operations)

integer vIntCnt;
list a = [1,2,3,4];
llOwnerSay( (string)llList2List( a, vIntCnt, vIntCnt += 3 ) );

will yield "1234" (left to right order of parameter evaluation)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
08-07-2009 05:51
grrrrrrrrr Still seems screwy though:
CODE

list stuff =
["one", 1, "two", 2, "three", 3, "four", 4, "five", 5, "six", 6, "seven", 7, "eight", 8, "nine", 9, "ten", 10,
"eleven", 11, "twelve", 12, "thirteen", 13, "fourteen", 14];
default {
state_entry() {
integer i = 0;
llOwnerSay(llList2String(stuff, i) + " : " + llList2String(stuff, ++i));
llOwnerSay(llList2String(stuff, 0) + " : " + llList2String(stuff, 1));
}
}

returns:
[5:33] Object: 1 : 1
[5:33] Object: one : 1
CODE

list stuff =
["one", 1, "two", 2, "three", 3, "four", 4, "five", 5, "six", 6, "seven", 7, "eight", 8, "nine", 9, "ten", 10,
"eleven", 11, "twelve", 12, "thirteen", 13, "fourteen", 14];
default {
state_entry() {
integer i = 0;
llOwnerSay(llList2String(stuff, ++i) + " : " + llList2String(stuff, i));
llOwnerSay(llList2String(stuff, 0) + " : " + llList2String(stuff, 1));
}
}

returns:
[5:36] Object: 1 : one
[5:36] Object: one : 1
CODE

list stuff =
["one", 1, "two", 2, "three", 3, "four", 4, "five", 5, "six", 6, "seven", 7, "eight", 8, "nine", 9, "ten", 10,
"eleven", 11, "twelve", 12, "thirteen", 13, "fourteen", 14];
default {
state_entry() {
integer i = 0;
llOwnerSay(llList2String(stuff, ++i) + " : " + llList2String(stuff, --i));
llOwnerSay(llList2String(stuff, 0) + " : " + llList2String(stuff, 1));
}
}

returns:
[5:39] Object: one : 14
[5:39] Object: one : 1
CODE

list stuff =
["one", 1, "two", 2, "three", 3, "four", 4, "five", 5, "six", 6, "seven", 7, "eight", 8, "nine", 9, "ten", 10,
"eleven", 11, "twelve", 12, "thirteen", 13, "fourteen", 14];
default {
state_entry() {
integer i = 0;
llOwnerSay(llList2String(stuff, i) + " : " + llList2String(stuff, i + 1));
llOwnerSay(llList2String(stuff, 0) + " : " + llList2String(stuff, 1));
}
}

returns:
[5:44] Object: one : 1
[5:44] Object: one : 1
CODE

list stuff =
["one", 1, "two", 2, "three", 3, "four", 4, "five", 5, "six", 6, "seven", 7, "eight", 8, "nine", 9, "ten", 10,
"eleven", 11, "twelve", 12, "thirteen", 13, "fourteen", 14];
default {
state_entry() {
integer i = 0;
llOwnerSay(llList2String(stuff, --i) + " : " + llList2String(stuff, ++i));
llOwnerSay(llList2String(stuff, 0) + " : " + llList2String(stuff, 1));
}
}

finally returns:
[5:42] Object: one : 1
[5:42] Object: one : 1
Completely strange and goofy but then I guess the next logical step would be:
CODE

list stuff =
["one", 1, "two", 2, "three", 3, "four", 4, "five", 5, "six", 6, "seven", 7, "eight", 8, "nine", 9, "ten", 10,
"eleven", 11, "twelve", 12, "thirteen", 13, "fourteen", 14];
default {
state_entry() {
integer i = 0;
llOwnerSay(llList2String(stuff, i++) + " : " + llList2String(stuff, i));
llOwnerSay(llList2String(stuff, 0) + " : " + llList2String(stuff, 1));
}
}

NOPE! No logic there either, instead it is incrementing i before processing anything else in that line and you end up with:
[5:49] Object: one : one
[5:49] Object: one : 1
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-07-2009 06:05
Just avoid using expressions with side effects if you're using the effected variable more than once in a statement. And don't use postincrement if you're not absolutely sure that's what you need.

Everyone using a C-like language should really have some real C under your belt. After invoking nasal demons a few times it becomes second nature to avoid this kind of shenanigan.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
08-07-2009 08:11
heh bend your mind on this...

CODE

list ABC = ["a", "A", "b", "B", "c", "C"];

integer count = ([] != ABC);
while (count++){
llOwnerSay( llList2String( ABC, count++ ) + ":" + llList2String( ABC, ++count-- ) );
}
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-07-2009 09:01
Anyone who writes "++count--" is just screaming for a reaming by the f***-up fairy.

I've written code that uses Duff's Device, I've used shifts for multiplication by non-powers-of-two. I LIKE FORTH. And even I wouldn't do that.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
08-07-2009 14:13
From: Argent Stonecutter
Anyone who writes "++count--" is just screaming for a reaming by the f***-up fairy.

I've written code that uses Duff's Device, I've used shifts for multiplication by non-powers-of-two. I LIKE FORTH. And even I wouldn't do that.

all in good fun.... I'd never do that in production code, but it illustrates the crazy that can come out if you get too wrapped up in trying to work around order of operations instead of using it to your advantage.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-07-2009 14:30
From: Void Singer
all in good fun.... I'd never do that in production code, but it illustrates the crazy that can come out if you get too wrapped up in trying to work around order of operations instead of using it to your advantage.
You should never write any code that depends on the order of evaluation of an expression. If it means splitting the line up into two statements, do it.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore