llDialog

From Second Life Wiki
Revision as of 02:42, 23 January 2008 by Huney Jewell (talk | contribs) (Dialog button chat range clarified)
Jump to navigation Jump to search

Summary

Function: llDialog( key avatar, string message, list buttons, integer chat_channel );
1.0 Forced Delay
10.0 Energy

Shows a dialog box on the avatar screen with message and buttons.

• key avatar avatar UUID
• string message
• list buttons
• integer chat_channel

When a button is pressed, the avatar shouts the button text on chat_channel.
The position of the chat is where the prim was when the dialog box was created.

Button Order
9   10 11
6 7 8  
3 4 5
0 1 2
Channel Constant Description
DEBUG_CHANNEL 0x7FFFFFFF Chat channel reserved for script debugging and error messages, broadcasts to all nearby users.
PUBLIC_CHANNEL 0x0 Chat channel that broadcasts to all nearby users. This channel is sometimes referred to as: open chat, local chat and public chat.

Caveats

  • This function causes the script to sleep for 1.0 seconds.
  • There is no way by script to kill a dialog box.
  • There is no way for the script to detect if the user clicked the small "ignore" button (no chat is generated as a result of pressing this button).
  • There is no way to distinguish the input from a dialog box and regular chat made by the same user.
    • It is important to expect that the response may not be one of the buttons.
  • If the prim moves out of shout range of where the dialog was created it will not be able to hear the response.
    • This limitation affects attachments too if the wearer moves out of shout range of where the dialog box was created.

message limits

  • If it exceeds 8 lines a scroll bar will appear.
  • message must be less than 512 bytes and not empty. Otherwise it will shout an error on DEBUG_CHANNEL.

buttons limits

  • If buttons is an empty list, it will default to as if it were ["OK"]
  • An error will be shouted on DEBUG_CHANNEL if...
    • More than 12 buttons.
    • any list item is not a string.
    • any list item string length (in bytes) is zero or greater than 24.

Examples

<lsl>integer channel = 1000; list pairs = [];

default {

   state_entry()
   {
       llListen(channel,"", "","");
   }
   touch_start(integer count)
   {
       llDialog(llDetectedKey(0), "This is a test dialog.\n\nPlease choose one of the below options.",
                ["Yes", "No", "0", "1"], channel);
   }
   
   listen(integer chan, string name, key id, string mes)
   {
       if(id == llGetOwnerKey(id))//won't listen to objects unless they aren't in the region.
           llSay(0,name + " (" + (string)llGetObjectDetails(id, (list)OBJECT_POS) + ") chose option " + mes);
   }
}</lsl>

Useful Snippets

<lsl>//Compact function to put buttons in "correct" human-readable order integer channel;

list order_buttons(list buttons) {

   return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4)
       + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);

}

default {

   state_entry()
   {   // Create random channel within range [-1000000000,-2000000000]

channel = (integer)(llFrand(-1000000000.0) - 1000000000.0);

llListen(channel,"", "","");

   }
   touch_start(integer total_number)
   {
       llDialog(llDetectedKey(0),"\nPlease choose an option:\n",

order_buttons(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]),channel);

   }
   listen(integer _chan, string _name, key _id, string _option)
   {
       llSay(0, _name + " chose option " + _option);
   }

}</lsl>

Notes

It is a good idea to use a very negative channel (if never more negative than the most negative 32-bit integer that is -2,147,483,648), e.g., <lsl>// Create random channel within range [-1000000000,-2000000000] integer channel = (integer)(llFrand(-1000000000.0) - 1000000000.0);

llDialog(llDetectedKey(0), "Please choose one of the below options:",

   ["Yes", "No", "0", "1"], channel);</lsl>

It is impossible for an avatar to chat on a negative channel, and extremely unlikely that some other object would accidently say something on such a channel. (Of course, the intended target of the message must be set to 'listen' on this channel.)

Deep Notes

Signature

function void llDialog( key avatar, string message, list buttons, integer chat_channel );