Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Format a list of buttons 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.

// 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);

Lex: Dialogues with any number of buttons (multiple of 3 and otherwise) do work correctly, that's what the second for{} loop does. Copy and paste the code into a script, the state I put in there runs a demo.
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
03-27-2005 09:31
Good stuff. Yes, I had noticed that. Very annoying :/ For those that aren't clear on what llDialog does with your button order: first, it wraps your list into rows of three items each. Next, it displays these rows in reverse order. Wha?

The worst part is that the last row might have less than 3 buttons in it, and it'll appear at the top with less than 3 buttons, which makes it look strange. Huns' code doesn't deal with this, because, as far as I can tell, there's no way to get around it other than to make sure you have a multiple of 3 buttons if you're using more than 3.

edit-going to let this one live here cause i was late in getting the discussion thread up. All other comments/questions should be posted at /54/ac/40117/1.html. Cool thanks, ne
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
The discussion thread
03-27-2005 10:31
is located here. have at it :)
i've got nothing. ;)