| 示例1 // When the prim is touched, give the toucher the option of killing the prim.
 
integer gListener;     // Identity of the listener associated with the dialog, so we can clean up when not needed
 
default
{
    touch_start(integer total_number)
    {
        // Kill off any outstanding listener, to avoid any chance of multiple listeners being active
        llListenRemove(gListener);
        // get the UUID of the person touching this prim
        key user = llDetectedKey(0);
        // Listen to any reply from that user only, and only on the same channel to be used by llDialog
        // It's best to set up the listener before issuing the dialog
        gListener = llListen(-99, "", user, "");
        // Send a dialog to that person. We'll use a fixed negative channel number for simplicity
        llDialog(user, "\nDo you wish this prim to die?", ["Yes", "No" ] , -99);
        // Start a one-minute timer, after which we will stop listening for responses
        llSetTimerEvent(60.0);
    }
    listen(integer chan, string name, key id, string msg)
    {
        // If the user clicked the "Yes" button, kill this prim.
        if (msg == "Yes")
            llDie();
        // The user did not click "Yes" ...
        // Make the timer fire immediately, to do clean-up actions
        llSetTimerEvent(0.1);        
    }
    timer()
    {
        // Stop listening. It's wise to do this to reduce lag
        llListenRemove(gListener);
        // Stop the timer now that its job is done
        llSetTimerEvent(0.0);// you can use 0 as well to save memory
    }
}
示例2
 string mainMenuDialog = "\nWhich settings would you like to access?\nClick \"Close\" to close the menu.\n\nYou are here:\nMainmenu";
list mainMenuButtons = ["sub 01", "sub 02", "Close"];
 
string subMenu_01_Dialog = "\nClick \"Close\" to close the menu.\nClick \"-Main-\" to return to the main menu.\n\nYou are here:\nMainmenu > sub 01";
list subMenu_01_Buttons = ["action 01a", "action 01b", "Close", "-Main-"];
 
string subMenu_02_Dialog = "\nClick \"Close\" to close the menu.\nClick \"-Main-\" to return to the main menu.\n\nYou are here:\nMainmenu > sub 02";
 
list subMenu_02_Buttons = ["action 02a", "action 02b", "Close", "-Main-"];
 
integer dialogChannel;
integer dialogHandle;
 
open_menu(key inputKey, string inputString, list inputList)
{
    dialogChannel = (integer)llFrand(DEBUG_CHANNEL)*-1;
    dialogHandle = llListen(dialogChannel, "", inputKey, "");
    llDialog(inputKey, inputString, inputList, dialogChannel);
    llSetTimerEvent(30.0);
}
 
close_menu()
{
    llSetTimerEvent(0.0);// you can use 0 as well to save memory
    llListenRemove(dialogHandle);
}
 
default
{
    on_rez(integer start_param)
    {
        llResetScript();
    }
 
    touch_start(integer total_number)
    {
        key id = llDetectedKey(0);
        // Ensure any outstanding listener is removed before creating a new one
        close_menu();
        open_menu(id, mainMenuDialog, mainMenuButtons);
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if(channel != dialogChannel)
            return;
 
        close_menu();
 
        if(message == "-Main-")
            open_menu(id, mainMenuDialog, mainMenuButtons);
 
        else if(message == "sub 01")
            open_menu(id, subMenu_01_Dialog, subMenu_01_Buttons);
 
        else if(message == "sub 02")
            open_menu(id, subMenu_02_Dialog, subMenu_02_Buttons);
 
        else if (message == "action 01a")
        {
            //do something
            open_menu(id, subMenu_01_Dialog, subMenu_01_Buttons);
        }
        else if (message == "action 01b")
        {
            //do something else
 
            //maybe not re-open the menu for this option?
            //open_menu(id, subMenu_01_Dialog, subMenu_01_Buttons);
        }
        else if (message == "action 02a")
        {
            //do something
            open_menu(id, subMenu_02_Dialog, subMenu_02_Buttons);
        }
        else if (message == "action 02b")
        {
            //do something else
            open_menu(id, subMenu_02_Dialog, subMenu_02_Buttons);
        }
    }
 
    timer()
    {
        close_menu();
    }
}
 |