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);
}
}
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.