LSL Wiki Mirror : llDialog

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings ::
llDialog(key id, string message, list buttons, integer chat_channel)

Shows the user specified by id a popup dialog box (in the upper right corner of their SecondLife window) containing message and buttons (and an "Ignore" button). Selecting any of the buttons will cause the avatar to say the text of that button on channel chat_channel.

Even though the chat will originate with the user's name and key, the chat position will be centered at the object calling llDialog. This ensures the object will be always within listening range of the answer.

Using DEBUG_CHANNEL as the chat_channel will cause avatar to say the button name on the public channel, rather then on the debug channel as one might expect.

Limits to message:

Limits to buttons:

If the user selects "Ignore", the script will not receive an answer, so implement a timeout (recommended) or allow the dialog to be restartable from anywhere.

Notes


Example

// when touched, present a dialog with four color choices

integer CHANNEL = 42; // dialog channel
list MENU_MAIN = ["Sit", "Stand", "Fly", "Cheat", "Options..."]; // the main menu
list MENU_OPTIONS = ["Cherry", "Blueberry", "Vinegar", "Slime", "Chips", "Salad", "...Back"]; // a submenu

default {
    state_entry() {
        llListen(CHANNEL, "", NULL_KEY, ""); // listen for dialog answers (from multiple users)
    }
    
    touch_start(integer total_number) 
    {
        llDialog(llDetectedKey(0), "What do you want to do?", MENU_MAIN, CHANNEL); // present dialog on click
    }
    
    listen(integer channel, string name, key id, string message) 
    {
        if (llListFindList(MENU_MAIN + MENU_OPTIONS, [message]) != -1)  // verify dialog choice
        {
            llSay(0, name + " picked the option '" + message + "'."); // output the answer
            if (message == "Options...") 
                llDialog(id, "Pick an option!", MENU_OPTIONS, CHANNEL); // present submenu on request
            else if (message == "...Back") 
                llDialog(id, "What do you want to do?", MENU_MAIN, CHANNEL); // present main menu on request to go back
            // here you have the name and key of the user and can easily verify if they have the permission to use that option or not
            else if (message == "Sit") 
                llSay(0, "This is where stuff would happen if this wasn't just an example");
        } else 
            llSay(0, name + " picked invalid option '" + llToLower(message) + "'."); // not a valid dialog choice
    }
}

//Compact function to put buttons in "correct" human-readable order ~ Redux
list order_buttons(list buttons)
{
    return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
}

//Function that puts buttons in "correct" human-readable order without relying on intelligent higher order list functions ~ Redux
list order_buttons(list buttons)
{
        integer offset;
        list fixt;
        while((offset = llGetListLength(buttons)))
        {
            fixt += llList2List(buttons, (offset = -(offset%3 + 1)), -1);
            buttons = llDeleteSubList(buttons, offset, -1);
        }
        return buttons;
}

Q & A
Q: What is the equivelant range of llDialog (whisper, say, shout, regionsay)?
A: Responding to the dialog will work as if the object were to use llSay(channel,message), where 'channel' is the channel specified by llDialog and 'message' is the text that was on the button choosen. This means the range is a 20-meter radius centered on the object.

Q: Is there a way to extend (or narrow) the range?
A: Not directly. You could use the listen event trigger a llShout or llRegionSay when it hears a dialog choice, but it doesn't appear to be possible to narrow the range unless you do something equivalent to an if/else and llVecDist.


Functions | Agent/Avatar | Chat | Communications | User-Interface
There are 5 comments on this page. [Display comments/form]