Dialog Control

From Second Life Wiki
Jump to navigation Jump to search

Functions List

Basic Dialog Functionalities

  1. Standard dialog with buttons. If there are more than 12 buttons, BACK/NEXT button will be added automatically! In that case, the last button on the list will be used as Close/Cancel button.
    • dialog(key id, string message, list buttons, list returns);
  2. To recall last dialog (only work if a dialog has been called before):
    • dialogReshow();
  3. To cancel current dialog; Currently displayed dialog will give no response when clicked.
    • dialogCancel();

Menus Control

  1. Initialize menus control using:
  2. Using "packDialogMessage" function to generate new menu, and add it to menus list:
    • llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(....), "MenuName");
    • While "MenuName" is the name of this menu, ie: MainMenu
  3. To make a dialog button show a sub-menu, use following as return value of the button:
    • MENU_<name>
    • Replace "<name>" with the actual name of the added menu (without parenthesis).
  4. Repeat (2) and (3) for all menus you want
  5. To show a menu, use:
    • llMessageLinked(LINK_THIS, lnkMenuShow, "MenuName", llGetOwner());
    • Where "MenuName" is the name of menu to show. To show last-used menu, leave this field empty.
  6. Dialog will return value the same way as usual call to Nargus Dialog Module script.

Sample Scripts

  1. OnTouchSelectTexture (Tiyuk Quellmalz)


If anyone uses this module, please IM Nargus Asturias, I'd love to hear what you think.

Scripts

Basic Usage Examples

Dialog Usage

<lsl> // READ ME: // To see this sample in action; // Put "Nargus Dialog Control" along with this script in a prim and touch.

// ********** DIALOG FUNCTIONS ********** // Dialog constants integer lnkDialog = 14001; integer lnkDialogResponse = 14002; integer lnkDialogTimeOut = 14003;

integer lnkDialogReshow = 14011; integer lnkDialogCancel = 14012;

string seperator = "||"; integer dialogTimeOut = 0;

string packDialogMessage(string message, list buttons, list returns){

   string packed_message = message + seperator + (string)dialogTimeOut;
   
   integer i;
   integer count = llGetListLength(buttons);
   for(i=0; i<count; i++){
       string button = llList2String(buttons, i);
       if(llStringLength(button) > 24) button = llGetSubString(button, 0, 23);
       packed_message += seperator + button + seperator + llList2String(returns, i);
   }
   return packed_message;

}

dialogReshow(){llMessageLinked(LINK_THIS, lnkDialogReshow, "", NULL_KEY);} dialogCancel(){

   llMessageLinked(LINK_THIS, lnkDialogCancel, "", NULL_KEY);
   llSleep(1);

}

dialog(key id, string message, list buttons, list returns){

   llMessageLinked(LINK_THIS, lnkDialog, packDialogMessage(message, buttons, returns), id);

// ********** END DIALOG FUNCTIONS **********


default{

   state_entry(){
       llSetText("Touch me to show dialog", <1,1,1>, 1);
   }
   link_message(integer sender_num, integer num, string str, key id){
       if(num == lnkDialogTimeOut){
           llOwnerSay("Menu time-out. Please try again.");
           state default;
       }else if(num == lnkDialogResponse){
           llWhisper(0, str);
       }
   }
   
   touch_start(integer num_detected){
       dialog(llDetectedKey(0),
       
           // Dialog message here
           "Messages go here",
           
           // List of dialog buttons
           [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, "Close" ],
           // List of return value from the buttons, in same order
           // Note that this value do not need to be the same as button texts
           [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, "X" ]
       );
   }

} </lsl>

Menus Usage

<lsl> // READ ME: // To see this sample in action; // Put "Nargus Dialog Control v1.80" along with this script // in a prim and touch.

// Dialog constants integer lnkDialog = 14001; integer lnkDialogResponse = 14002; integer lnkDialogTimeOut = 14003;

integer lnkDialogReshow = 14011; integer lnkDialogCancel = 14012;

integer lnkMenuClear = 15001; integer lnkMenuAdd = 15002; integer lnkMenuShow = 15003;

string seperator = "||"; integer dialogTimeOut = 0;

// ********** DIALOG FUNCTIONS ********** string packDialogMessage(string message, list buttons, list returns){

   string packed_message = message + seperator + (string)dialogTimeOut;
   
   integer i;
   integer count = llGetListLength(buttons);
   for(i=0; i<count; i++) packed_message += seperator + llList2String(buttons, i) + seperator + llList2String(returns, i);
   return packed_message;

}

dialogReshow(){llMessageLinked(LINK_THIS, lnkDialogReshow, "", NULL_KEY);} dialogCancel(){

   llMessageLinked(LINK_THIS, lnkDialogCancel, "", NULL_KEY);
   llSleep(1);

} // ********** END DIALOG FUNCTIONS **********


default{

   state_entry(){
       llMessageLinked(LINK_THIS, lnkMenuClear, "", NULL_KEY);
       llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(
           "[ Main Menu ]\n" +
           "Messages go here",
           [ "BUTTON_1", "BUTTON_2", "BUTTON_3", "BUTTON_X" ],
           [ "MENU_SubMenu1", "MENU_SubMenu2", "MENU_SubMenu3", "EXIT" ]
       ), "MainMenu");
       llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(
           "[ Sub Menu 1 ]\n" +
           "Messages go here",
           [ "SUB_1_1", "SUB_1_2", "SUB_1_3", "MAIN MENU", "SUB_3", "BUTTON_X" ],
           [ "1.1", "1.2", "1.3", "MENU_MainMenu", "MENU_SubMenu3", "EXIT" ]
       ), "SubMenu1");
       llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(
           "[ Sub Menu 2 ]\n" +
           "Messages go here",
           [ "SUB_2_1", "SUB_2_2", "SUB_2_3", "MAIN MENU", "SUB_1", "BUTTON_X" ],
           [ "2.1", "2.2", "2.3", "MENU_MainMenu", "MENU_SubMenu1", "EXIT" ]
       ), "SubMenu2");
       llMessageLinked(LINK_THIS, lnkMenuAdd, packDialogMessage(
           "[ Sub Menu 3 ]\n" +
           "Messages go here",
           [ "SUB_3_1", "SUB_3_2", "SUB_3_3", "MAIN MENU", "SUB_2", "BUTTON_X" ],
           [ "3.1", "3.2", "3.3", "MENU_MainMenu", "MENU_SubMenu2", "EXIT" ]
       ), "SubMenu3");
       
       llSetText("Touch me to show menu", <1,1,1>, 1);
   }
   link_message(integer sender_num, integer num, string str, key id){
       if(num == lnkDialogTimeOut){
           llOwnerSay("Menu time-out. Please try again.");
       }else if(num == lnkDialogResponse){
           llWhisper(0, str);
       }
   }
   
   touch_start(integer num_detected){
       llMessageLinked(LINK_THIS, lnkMenuShow, "", llDetectedOwner(0));
   }

} </lsl>