Arranging llDialog buttons

Okay, back in Second Life! And/or OpenSim.

A purely Scripting-geekery post today, on a really niche topic.

When you get one of those blue dropdowns (or pop-ups, or drop-ins, depending on your viewer) with a number (up to twelve!) of buttons in them (when you touch a danceball for instance and it asks you what dance you want to do), the piece of LSL (Liden Scripting Language) that shows you that thing with those buttons is a built-in function called “llDialog“.

(All of the built-in functions start with “ll” which presumably stands for “Linden Lab”, but which has made many beginning LSL scripters, including Yers Truly, wonder how an identifier can start with eleven at all.)

One of the arguments to llDialog is, naturally enough, a list of the strings to put on the buttons. And the order in which the strings are copied from the list onto the buttons is… perhaps counterintuitive. For instance, if the list looks like:

[ "one", "two", "three", "four" ]

then the dialog as displayed will look like:

which might not be the first thing one would have guessed.

It basically starts at the bottom, filling rows upward as it goes, until it runs out of strings.

I have sometimes fiddled around to make things come out how I want them to manually, and more often have ignored the problem entirely and just not cared that the buttons were in a stupid order.

But for some reason today I got tired of it and decided to fix it; so here:

list arrange(list l) {
list outl = [];
integer n = llGetListLength(l);
do {
if (n<3) return outl + l;
n = n - 3;
outl = outl + llList2List(l, -3, -1);
if (n==0) return outl;
l = llList2List(l, 0, -4);
} while (TRUE);
return []; // UNREACHABLE
}

This will take a list in an order, and return a list in a different order such that if you pass the new list to llDialog, the labels on the buttons will be in the order that one might expect, left to right and up to down. As in for instance:

llDialog(avatar_id, prompt, arrange(button_list), channel);

It basically just divides the input list into pieces of size three, and then reverses them, with complications in case the input list isn’t equally divisible by three. And because if you ask LSL to copy the first through fourth-to-last (inclusive) elements of a three-element list, it silently copies the entire list rather than (as one might have expected) copying nothing. And because it doesn’t realize that a “do while(TRUE)” will never exit and without the unreachable line you get an error saying that not all code paths return a value. And because llGetListLength is said to be computationally expensive. And because LSL does let you use negative indices (roughly) on lists!

This works in both Second Life and OpenSim, because the scripting languages are extremely compatible for obvious reasons.

Many, many, implementations of this same algorithm no doubt exist all over the place :) but this is mine, for the moment and for what it’s worth!

2 Responses

  1. Haha! Man, I can relate to this post, Dale. I had to convince myself that I actually enjoyed figuring out how to arrange my buttons – like piecing together a weird jigsaw puzzle. But more like a maniac gluing strips of newspaper together in a nonsensical collage. Thanks for reminding me what a pain in the ass it is, haha. Stellar work on the script! As I read it, I just had to laugh at what it has to do to accomplish the goal. Funniest thing I’ve read in a while!
    Thanks much, Dale. This snippet will certainly help a lot of ll scripters. I just wonder if I can bring myself to make my list in order now. It’ll just seem so weird! Haha.

    • Haha, thanks! Yeah, I put these things up now and then both in case someone else finds it in a future search, and so I can in the future myself. :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: