|
Dylan Rickenbacker
Animator
Join date: 11 Oct 2006
Posts: 365
|
07-02-2009 12:19
Is there anything known about llListSort being unreliable? I'm working on a script where the function is called under a condition. Sometimes it works, sometimes it doesn't, and I can't figure out why. All the other functions under the condition are being called. I have tried whether giving the sorted list a new name would fix it, but no cigar. It still fails sometimes. The new list with the new name is called up later in the script, and it does have data, so I know llListSort has been called, otherwise the list would be empty. It just didn't do the sorting job. Any ideas? Here's the clause where the function comes in (don't want to post the entire script here, it's rather long): if(llToLower(msg) == "results") { results = llListReplaceList(results,[A],0,0); results = llListReplaceList(results,,4,4); results = llListReplaceList(results,[C],8, ; results = llListReplaceList(results,[D],12,12); results = llListReplaceList(results,[E],16,16); results = llListReplaceList(results,[F],20,20); results = llListReplaceList(results,[G],24,24); results = llListReplaceList(results,[H],28,2 ; results = llListReplaceList(results,,32,32); results = llListReplaceList(results,[J],36,36); results = llListReplaceList(results,[K],40,40); results = llListReplaceList(results,[L],44,44); results = llListReplaceList(results,[M],48,4 ; results = llListReplaceList(results,[N],52,52); results = llListReplaceList(results,[O],56,56); llSleep(1.0); results = llListSort(results,4,FALSE); llSleep(1.0); integer i = 0; integer rank = 1; integer dim = llGetInventoryNumber(INVENTORY_TEXTURE); llOwnerSay("Voting results:" ; while(rank <= dim) { if(llList2String(results,i+1) == "0" { i = i+4; } else { llOwnerSay((string)rank + ". " + llList2String(results,i+1) + " by " + llList2String(results,i+2) + " received " + llList2String(results,i) + " votes." ; i = i+4; rank++; } } resultsIn = TRUE; }
A to O are the integers the list is supposed to be sorted by in descending order.
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
07-02-2009 13:31
The list 'results' you put numbers in on every first place in each stride. is it filled at all? is llGetListLength( results ) >= 60, before you apply all these: results = llListReplaceList(results,.., .., ..); ?
_____________________
From Studio Dora
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-02-2009 13:36
well I'm not quite sure how it'll act if you have less/more than "O" strides in your list (does it pad out missing elements? which elements will fall on the sorted strides then there are more?)
if it has multiple data types falling on the stride element it may not sort correctly (I really haven't tested, but there some weird behavior in the sort regarding multiple types noted on the LSL Portal)
if it's a case of the stride number mismatching the insertion count you can take care of that by adding the sorting element in a loop (reference a string with your alphabet characters, and use llGetSubString with your counter)
although in the example there no sorting should happen, since you are adding sort elements in sorted order already... (sort only works on the first element of a stride, your first elements is in alphabetical order)
_____________________
| | . "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... | - 
|
|
Dylan Rickenbacker
Animator
Join date: 11 Oct 2006
Posts: 365
|
07-02-2009 15:57
To clarify, A to O are global variables for integers which are all set to 0 at declaration. They are still all at 0 when the "results" list is filled. Then they change in the voting process, after which the above example code is supposed to re-sort the list so that the entries with the most votes are at the top.
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
07-02-2009 16:18
From: Dylan Rickenbacker To clarify, A to O are global variables for integers which are all set to 0 at declaration. They are still all at 0 when the "results" list is filled. Then they change in the voting process, after which the above example code is supposed to re-sort the list so that the entries with the most votes are at the top. That is understood  But again, what are the other elements in the list at the time you put the A to O integers into it? Is the list filled? is llGetListLength( results ) >= 60, before you apply all these: results = llListReplaceList(results,.., .., ..); ?
_____________________
From Studio Dora
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-02-2009 21:26
sample data slices would help... and perhaps checking your alphabet list elements before replacement (and is the results list being purely built from the alphabet lists or does it already contain data of it's own? in which case you might just want to clear the results list and add the others instead of replacing)
_____________________
| | . "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... | - 
|
|
Dylan Rickenbacker
Animator
Join date: 11 Oct 2006
Posts: 365
|
07-03-2009 00:27
Thanks a lot! You put me on the right track. The sorting did indeed fail whenever not all 15 strides in the list were filled. Here's the new code which is working fine now: if(llToLower(msg) == "results") { integer dim = llGetListLength(results); integer entry; list votesList = ([A,B,C,D,E,F,G,H,I,J,K,L,M,N,O]); integer votesNum = 0; for (entry = 0; entry < dim; entry = entry+4) { results = llListReplaceList(results,llList2List(votesList,votesNum,votesNum), entry, entry); votesNum++; } results = llListSort(results,4,FALSE); integer i = 0; integer rank = 1; llOwnerSay("Voting results:"); while(rank <= dim/4) { llOwnerSay((string)rank + ". " + llList2String(results,i+1) + " by " + llList2String(results,i+2) + " received " + llList2String(results,i) + " votes."); i = i+4; rank++; } resultsIn = TRUE; }
|