Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Why won't a List output in the correct order?

Rock Vacirca
riches to rags
Join date: 18 Oct 2006
Posts: 1,093
09-27-2007 04:44
Hi guys,

I have a list containing vectors, around 30 at the moment, but could be up to 100. I have a touch event that uses a for loop, using the list index, that outputs the list to the screen via llSay.

Trouble is, the onscreen dump is never in the right order (of index position). In case this was lag induced, I inserted a llSleep of 1 sec between each iteration in the for loop, and I still get entries out of place. Sometimes the entry at index = 2 appears well after the entry at index = 20. What on earth causes this? Is there any way to overcome this?

Regards to all

Rock
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
09-27-2007 04:54
Rock,
It would really help to see your code or at least the section which applies. Sometimes these things occur due to a slight mistake in the code or the logic. Sounds to me like your modifying the count value within the for loop but that's just a stab in the dark without the code. I can't think of anything else off the top of my head as to why you wouldn't be able to access certain elements of a list in the correct order.
Regards,
nand
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
09-27-2007 05:22
I echo nand. I've seen a lot of weirdness in LSL, but never an out of order list (although I wouldn't be wildly surprised if I did).

Something that may come into play is the chat system you are using for debugging offers absolutely no guarantee of message delivery order, even when using sleeps. You might want to try:
From: someone
debug(((string) index) + " " + ((string) llList2Vector(list, index)));
to determine if the indicies are actually borked.

Oh, my "library" contains "debug(string s) { if(DEBUG) llSay(0, s); }" in case that wasn't obvious.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
I bet...
09-27-2007 09:28
...your packet loss is high. If it is, try reducing your bandwidth, and they will be more likely to come in the right order.

There is no guarantee messages will arrive in the same order that they are sent. Plan accordingly.
Rock Ryder
Registered User
Join date: 6 Oct 2006
Posts: 384
09-29-2007 03:19
Hi guys,

Here is the relevant code (number of vectors cut down for brevity-

list vectors = [<0,0,0>, <0,255,21>, <255,0,21>, <255,255,21>];
integer x;

default
{
state_entry()
{
llSay(0, "";);
}
touch_start(integer total_number)
{
llSay(0, "Listing vectors.... ";);
integer listlength = llGetListLength(vectors);

for (x = 0; x < listlength; x++)
{
vector element = llList2Vector(vectors, x);
integer X = (integer)element.x; // go the vector > integer > string route to produce integer vectors only, with no floating component
integer Y = (integer)element.y;
integer Z = (integer)element.z;
string myvector = ("<" + (string)X + "," + (string)Y + "," + (string)Z + ">";);
llOwnerSay(myvector);
}
}
}

When the llOwnerSay produces the list onscreen it is NOT in the same order as the order in the list. generally it is, but there are often two or more out of place, occasionally well out of place (like from 2nd to last).

How can I ensure that the screen listing will always be in the right sequence?

TIA

Rock
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
09-29-2007 08:23
In my experience llSay/llOwnerSay can come out in an unpredictable order. I think it's a lag thing. In extreme cases I've seen a message turn up long after it was first issued.

This is one possible solution:

list vectors = [<0,0,0>, <0,255,21>, <255,0,21>, <255,255,21>];
integer x;

default
{
state_entry()
{
llSay(0, "";);
}

touch_start(integer total_number)
{
llSay("Listing vectors.... ";);
integer listlength = llGetListLength(vectors);
string temp;

for (x = 0; x < listlength; x++)
{
vector element = llList2Vector(vectors, x);
integer X = (integer)element.x; // go the vector > integer > string route to produce integer vectors only, with no floating

component
integer Y = (integer)element.y;
integer Z = (integer)element.z;
temp = temp + "\n" + "<" + (string)X + "," + (string)Y + "," + (string)Z + ">";
//string myvector = ("<" + (string)X + "," + (string)Y + "," + (string)Z + ">";);
//llOwnerSay(myvector);
}
llOwnerSay(temp);
}

}

...but not very memory efficient and temp will be restricted to 1023 bytes. Works in this case though. :D