Saturday, January 13, 2007

LSL challenges: numerical data entry

LSL is all about compromises. It's powerful and allows you to customize SL in a way I never thought would be available to a "normal user" in a MMORPG-type setting, but it's limited enough that it's challenging to do things I'd often take for granted.

User interface is particularly limited. Not only isn't there a way to do fancy things like drop-down menus, radio buttons, checkboxes, etc., but it's actually not even possible to enter a number in a dedicated text-entry field.

You can get around this by setting up "listens" on particular channels, and entering commands on the chat line, like "\1 flare 45" to set the flare angle to 45 degrees, but I think something much more user-friendly would be to have a llDialog window, click the "Flare" button, and then enter 45.

For number entry, I tried the following to use llDialog and its customizable buttons as a numeric keypad:

integer LISTEN_CHANNEL = 34687;
list NUMBER_PAD = [ "0", "OK", "Cancel", "7", "8", "9", "4", "5", "6", "1", "2", "3" ];
string entry = "";

default {
state_entry() {
llListen(LISTEN_CHANNEL, "", NULL_KEY, "");
}

touch_start(integer total_number) {
entry = "";
llDialog(llDetectedKey(0), "Entered: "+entry+"_", NUMBER_PAD, LISTEN_CHANNEL);
}

listen(integer channel, string name, key id, string message) {
if ((channel == LISTEN_CHANNEL) && (llListFindList(NUMBER_PAD, [message]) != -1)) {
if (message == "Cancel") {
entry = "";
llDialog(id, "Entered: "+entry+"_", NUMBER_PAD, LISTEN_CHANNEL);
}
else if (message == "OK") {
llOwnerSay("The number "+entry+"was entered.");
}
else {
entry += message;
llDialog(id, "Entered: "+entry+"_", NUMBER_PAD, LISTEN_CHANNEL);
}
}
}
}
It creates a numeric keypad with the digits 0-9, an "OK" button, and a "Cancel" button. It builds up an entry as you press digits, and then displays the result after you press "OK".

It works, but I learned that llDialog has a built-in delay (1 second, I think), and the constant re-drawing of the dialog window is a little distracting. It could be used, but it's not very elegant.

Johanna Hyacinth suggested hijacking the payment dialog, which allows a free-form integer entry window, but I think people would get suspicious about "paying" L$ just to enter a number, even if the L$ got returned.

An HUD is the fancy option, but for me anyhow, wouldn't be fun to write.

Maybe spoken chat-driven number entry isn't so bad.

(Addendum: this blog style template really doesn't like long lines of code. Anyone know a better way to post code snippets?)