Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Format so that llDialog displays them in the correct order.

Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
03-27-2005 01:41
Ever notice that when you build a long menu with llDialog(), the buttons come out in some kind of crazy wierd upside-down order? I decided to write a function that formats a list so that it comes out in the right order in the dialog.

CODE
// by Huns Valen 2005
// Released under the terms of the LGPL.

// Manipulate an array of buttons so that llDialog() displays them in the correct order.
// By default, llDialog() mangles the order of the buttons in an upside-down pattern.
list menuFormat(list theButtons) {
list btnOut;
integer nButtons = llGetListLength(theButtons);
integer nLastRow = nButtons % 3;
integer lastRow = nButtons - nLastRow;
integer row;

// Reverse the array in chunks of 3, since an llDialog() row is 3 buttons.
// We do not handle the first line of buttons, since they may not be a multiple of 3.
for(row = nButtons; row >= nLastRow; row -= 3) {
btnOut += llList2List(theButtons, row, row + 2);
}

// Now handle the first line of buttons, which can be 1, 2, or 3 buttons long.
for(row = 0; row < nLastRow; row++) {
btnOut += llList2String(theButtons, row);
}

return btnOut;
}

default {
state_entry() {
list theButtons = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B"];
list formatted = menuFormat(theButtons);
// Uncomment this to see it the wierd default way:
//llDialog(llGetOwner(), llDumpList2String(theButtons, "\n"), theButtons, 1);

// Correctly formatted way:
llDialog(llGetOwner(), llDumpList2String(theButtons, "\n"), formatted, 1);
}
}
Chandra Page
Build! Code. Sleep?
Join date: 7 Oct 2004
Posts: 360
03-28-2005 16:40
Great utility function, Huns. The llDialog work I've done so far has been a frightening pain in the butt every time I have to add or remove a button from the interface; this would have saved me a lot of time rewriting my lists. Thanks!
_____________________
Come visit the In Effect main store and café
Drawbridge (160, 81)
Particle effects, fashion, accessories, and coffee!
On the Web at SL Exchange and SL Boutique
Olmy Seraph
Valued Member
Join date: 1 Nov 2004
Posts: 502
03-28-2005 18:41
Oh sweet mother of mercy! I could have really used this when I was going nutso on a dialog system last month.

I've heard rumors that LL will be creating a better dialog system for scripts. Powers know there's a lot of room for improvement!
_____________________
Some people are like Slinkies... not really good for anything, but they sure bring a smile to your face when you push them down the stairs.
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
03-29-2005 00:24
Sad thing is, is when LL does change something, every script using this function will break. They should've made it so that the dialog buttons display in the order of llDialog's button list in the first place :(

Still, awesome snippet Huns. :)
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
Graham Mondrian
Registered User
Join date: 16 Mar 2005
Posts: 59
03-31-2005 14:04
good job :)