Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sorted Dialog Buttons

Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
09-10-2007 10:28
I've gotten myself into one of those situations where you've worked on a problem so long and run into so many dead ends, you can't think straight, and the solution, though it may be straightforward, is lost in the jumble of discarded attempts.

It all starts with the diabolical fiend who wrote the llDialog() function. I know s/he did the button ordering that way just to drive scripters insane. May s/he be forced to write an RPG compiler in Malbolge using vi while listening to ten straight hours of "Don't Worry, Be Happy!" followed by the greatest hits of William Shatner and Tammy Faye Baker.

I have a sorted list, e.g. ["Apples", "Bananas", "Cherries", "Dates",.....] of arbitrary length. I want to chop it up into submenus of 10 buttons or less, tack on "Prev" and "Next" buttons at the end of each submenu...and have the buttons displayed in the original sorted order.

The chopping and tacking, no problem. Got that licked in 5 minutes. The ordering.... AAAUUUUUGGGGGHHH!

I actually came up with something partially workable:

CODE

for (x=0; x<llGetListLength(lstTextures); x+=10) {
lstSubList = llList2List(lstTextures, x, x+9);
lstSubList =
llList2List(lstSubList, 9, 10) +
llList2List(lstSubList, 3, 5) +
llList2List(lstSubList, 6, 8) +
llList2List(lstSubList, 0, 2);
lstSubList = llListInsertList(lstSubList, ["Prev", "Next"], 1);
lstMenus = (lstMenus=[]) + lstMenus + [llDumpList2String(lstSubList, "|")];
}


However, it only works on pages that have a full 10 buttons. Anything less and it gets messed up. And then my brain melted.

Could some kind soul help me out with a solution?
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
09-10-2007 10:37
Pad the list with blank space entries until the list is evenly divisible by 10.
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
09-10-2007 10:45
Thanks for the reply, but I don't really want blank buttons on the menu.
Salvador Nakamura
http://www.sl-index.com
Join date: 16 Jan 2007
Posts: 557
09-10-2007 11:13
Hi , i dont feel like writing it, but perhaps it will help anyways, what if..

you would place the buttons in (CSV) comma sepperated values string, then use for loops like:

(x=where_whe_left; x <= where_we_left+9; ++x)

to create the buttons from this list, untill all buttons have passed ?
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
09-10-2007 11:45
More of a Tell than a Tip, but here you go:

CODE

// one day the php tags WILL work again...
// one day the php tags WILL work again...
// /me bangs head on keyboard

list srcList = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"];
list tgtList;

list orderList(list srcList)
{
integer i;
integer j;
integer k;
integer len;
list tmpList = [];

len = llGetListLength(srcList) - 1;

for(i = 1; i <= 4; i++)
B {
for(j = 1; j <= 3; j++)
{
k = len - (3 * i) + j;
if (k >= 0 && k <= len) tmpList = (tmpList=[]) + tmpList + [llList2String(srcList, k)];
}
}

srcList = tmpList;
return(srcList);
}

default
{
touch_start(integer total_number)
{
tgtList = orderList(srcList);
llDialog(llGetOwner(), "Sorted", tgtList, -1);
}
}


But I'd be interested to see someone make it tighter. :)
Lyn Mimistrobell
(waiting)
Join date: 11 Jan 2007
Posts: 179
09-10-2007 14:17
myList = llListSort(myList, 1, TRUE);

http://rpgstats.com/wiki/index.php?title=LlListSort
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
09-10-2007 15:27
Salvador: I'm not sure I follow what you're saying; it looks like you're proposing a way to chop up the list, which I already have. However, you got me to thinking a little differently about the problem (and then I went for a walk, which helped, too) and I came up with a solution.

Pale: I didn't really dig into your example, but thanks for replying anyway.

Lyn: I'm guessing you've never worked with llDialog :) A sorted list does not result in sorted buttons! But thank you anyway.

OK, here's what works:

(Some day the Lindens will turn BBCode back on!)
CODE

for (x=0; x<llGetListLength(lstTextures); x+=10) {
lstTemp = [];
lstSubList = llList2List(lstTextures, x, x+9) + ["Prev", "Next"];

do {
lstTemp = (lstTemp=[]) + lstTemp + llList2List(lstSubList, -3, -1);
lstSubList = llDeleteSubList(lstSubList, -3, -1);
} while (llGetListLength(lstSubList) > 0);

lstMenus = (lstMenus=[]) + lstMenus + [llDumpList2String(lstTemp, "|")];
}
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
09-10-2007 22:06
To clarify for Lyn, a button list is assigned to the dialog right-to-left, bottom-to-top. So if you pass it the list [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" ], the buttons will be arranged:

( 10 ) ( 11 ) ( 12 )
( 7 ) ( 8 ) ( 9 )
( 4 ) ( 5 ) ( 6 )
( 1 ) ( 2 ) ( 3 )

Which is not what Siann wants, which is top-to-bottom sorting.
Carrah Rossini
Registered User
Join date: 8 Apr 2007
Posts: 17
09-10-2007 22:13
I believe:

myList=llListSort(llListSort(myList,1,TRUE),3,FALSE);

should work (and if it does, why? :) ).
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
09-11-2007 05:20
That was one of my early attempts. You end up with:

C B A
F E D
I H G

etc.
Carrah Rossini
Registered User
Join date: 8 Apr 2007
Posts: 17
09-11-2007 07:15
Sian, not sure what I'm doing wrong then, since it works for me; make a new object, then paste the code below into it, then click it.

default{
touch_start(integer total_number){
list meep=["C","B","A","F","E","D","I","H","G"];
meep=llListSort(llListSort(meep,1,TRUE),3,FALSE);
llDialog(llDetectedKey(0),"Its Sorted",meep,12345);
}
}

the above results in:

(A) (B) (C)
(D) (E) (F)
(G) (H) (I)

see the attachment.
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
09-11-2007 11:26
@Carrah

CODE

list srcList = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"];
list tgtList;

default
{
touch_start(integer total_number)
{
tgtList = llListSort(llListSort(srcList, 1, TRUE), 3, FALSE);
llDialog(llGetOwner(), "Sorted", tgtList, -1);
}
}


Gives me:

< J >
< G >< H >< I >
< D >< E >< F >
< A >< B >< C >

Whereas what we're after is:

< A >
< B >< C >< D >
< E >< F >< G >
< H >< I >< J >

Starting with ["C","B","A","F","E","D","I","H","G"] is cheating! :p


@Siann

CODE

list srcList = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"];
list tgtList;

list orderList(list srcList)
{
list lstTemp = [];

do
{
lstTemp = (lstTemp=[]) + lstTemp + llList2List(srcList, -3, -1);
srcList = llDeleteSubList(srcList, -3, -1);
} while (llGetListLength(srcList) > 0);

srcList = lstTemp;
return(srcList);
}

default
{

touch_start(integer total_number)
{
tgtList = orderList(srcList);
llDialog(llGetOwner(), "Sorted", tgtList, -1);
}

}


Worked for me, and it sure looks neater then my example. Although, I'm not sure if the llDeleteSubList is more expensive than just appending the list elements.
Carrah Rossini
Registered User
Join date: 8 Apr 2007
Posts: 17
09-11-2007 13:47
From: Pale Spectre
@Carrah

Starting with ["C","B","A","F","E","D","I","H","G"] is cheating! :p



hi Pale, not really, since I sort it first :)

I was rushing, you are right, llSortList doesn't like when the list length is not divisible by the stride (in this case 3)

So, here's a quick fix to that problem (that doesn't require loops or deletes)

default{
touch_start(integer total_number){

list source=["A","B","C","D","E","F","K","J","I","H","G"];
list target;

integer length=llGetListLength(source);

source=(source=[])+llListSort(source,1,TRUE);

if(length>2)target+=llListSort(llList2List(source,length%3,-1),3,FALSE);

if(length%3!=0)target+=llList2List(source,0,(length-1)%3);

llDialog(llDetectedKey(0),"Its Sorted",target,12345);
}
}

p.s. your code works, just posting an alternative.
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
/me takes his hat off to you.
09-11-2007 14:52
From: Carrah Rossini
p.s. your code works, just posting an alternative.
I know it works. :D

Heh, s'okay. It was me who invited a better solution and I think you've definitely succeeded. It tests out fine now. Cool job.
Carrah Rossini
Registered User
Join date: 8 Apr 2007
Posts: 17
09-11-2007 15:26
Just tried to be polite :) at which you've sadly failed.

Speaking of which, why is running a loop with multiple list additions, computing the lengths and finally doing deletes better than one pass through?
Day Oh
Registered User
Join date: 3 Feb 2007
Posts: 1,257
09-11-2007 15:45
list redux_owns_ibm(list buttons) { return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10); }

Thanks, Redux Dengaku (:
_____________________
Carrah Rossini
Registered User
Join date: 8 Apr 2007
Posts: 17
09-11-2007 15:52
From: Day Oh
list redux_owns_ibm(list buttons) { return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10); }

Thanks, Redux Dengaku (:


haha, brilliant!
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
09-12-2007 11:19
From: Pale Spectre
I know it works. :D

Heh, s'okay. It was me who invited a better solution and I think you've definitely succeeded. It tests out fine now. Cool job.

From: Carrah Rossini
Just tried to be polite :) at which you've sadly failed.

Speaking of which, why is running a loop with multiple list additions, computing the lengths and finally doing deletes better than one pass through?
I'm sorry. I acknowledge that your solution is better. I don't understand why you have a problem with this. :(
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
09-12-2007 15:13
From: Day Oh
list redux_owns_ibm(list buttons) { return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10); }

Thanks, Redux Dengaku (:

Ah, yes. Very close to my original almost-solution, and certainly more efficent than the loop with delete. The point is to attack it from the end of the list; that's what I wasn't getting at first.

Thanks everyone!