Difference between revisions of "LlTextBox"

From Second Life Wiki
Jump to navigation Jump to search
m
(Simplify and clarify examples, focusing on the target function)
Line 28: Line 28:
|examples=
|examples=
<lsl>
<lsl>
integer listener;
integer gListener;
 
// this is a user-function, it doesn't have a return type
remove_listener()
{
    llListenRemove(listener);
}
 
default
default
{
{
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
         key id = llDetectedKey(0);
         // See 'discussion' page for more comments on choosing a channel and possible left-open listener
         remove_listener();
         integer channel = -13572468;
 
         // "" saves byte-code over NULL_KEY
         integer randomChannel = ~(integer)llFrand(1000.0);
         gListener = llListen( channel, "", "", "");    
         listener = llListen(randomChannel, "", NULL_KEY, "");
         llTextBox(llDetectedKey(0), "Some info text for the top of the window...", channel);
 
         llTextBox(id, "Some info text for the top of the window...", randomChannel);
     }
     }
     listen(integer channel, string name, key id, string message)
     listen(integer channel, string name, key id, string message)
     {
     {
         // PUBLIC_CHANNEL has the integer value 0
         llListenRemove(gListener);
         llSay(PUBLIC_CHANNEL, "You wrote: " + message);
         llSay(0, "You wrote: " + message);
 
        remove_listener();
     }
     }
}
}
</lsl>
</lsl>
If the user hits "Enter" before clicking the "Submit" button, there will be a final carriage return in the message. This code removes it.
If the user hits "Enter" before clicking the "Submit" button, there will be a final carriage return in the message. In the rare event that this could be a problem, it is easily removed:-
<lsl>
<lsl>
integer listenHandle;
         if (llGetSubString(message, -1, -1) == llUnescapeURL("%0A") )
 
default
{
    touch_start(integer num_detected)
    {
         listenHandle = llListen(91, "", NULL_KEY, "");
 
        key id = llDetectedKey(0);
        llTextBox(id, "Type a message and click \"Submit\".", 91);
    }
 
    listen (integer channel, string name, key id, string message)
    {
        llListenRemove(listenHandle);
        integer messageLength = llStringLength(message);
        string lastMessageCharacter = llGetSubString(message, messageLength - 1, messageLength - 1);
 
        if (lastMessageCharacter == llUnescapeURL("%0A"))
        {
        //  Ignore final carriage return embedded in the message
             message = llGetSubString(message, 0, -2);
             message = llGetSubString(message, 0, -2);
            llSay(PUBLIC_CHANNEL, "Final carriage return removed.");
        }
        llSay(PUBLIC_CHANNEL, message);
    }
}
</lsl>
</lsl>



Revision as of 05:38, 30 December 2013

Summary

Function: llTextBox( key avatar, string message, integer channel );

Shows a dialog box on avatar's screen with the text message. It contains a text box for input, any text that is entered is said by avatar on channel when the "Submit" button is clicked.

• key avatar avatar UUID that is in the same region
• string message message to be displayed in the text box
• integer channel output chat channel, any integer value
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.
  • Not supported in official Linden Lab viewers prior to version 2.4, and some TPVs may not support it. Unsupported viewers will display a dialog box with a single option of "!!llTextBox!!".
  • There is no way by script to kill a text 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).
  • If the listening prim is out of the 20 meter range of the sending prim when the "Submit" button is pressed, it will not be able to hear the response.
    • This limitation affects attachments too if the wearer moves more than 20 meters from where the listener is located.
  • The textbox input is limited to 250 bytes (characters). This can be a problem for larger text input; if the input can be over 250 characters, you will have to accept it through chat.

message limits

  • If it exceeds 7 (Viewer 3) or 8 (Viewer 1) 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. One easy way to create an empty message is to use a line feed, as in <lsl>llTextBox(avatar_key," \n",dialog_channel);</lsl>
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> integer gListener; default {

   touch_start(integer total_number)
   {
       // See 'discussion' page for more comments on choosing a channel and possible left-open listener
       integer channel = -13572468;
       // "" saves byte-code over NULL_KEY
       gListener = llListen( channel, "", "", "");     
       llTextBox(llDetectedKey(0), "Some info text for the top of the window...", channel);
   }
   listen(integer channel, string name, key id, string message)
   {
       llListenRemove(gListener);
       llSay(0, "You wrote: " + message);
   }

} </lsl> If the user hits "Enter" before clicking the "Submit" button, there will be a final carriage return in the message. In the rare event that this could be a problem, it is easily removed:- <lsl>

       if (llGetSubString(message, -1, -1) == llUnescapeURL("%0A") )
           message = llGetSubString(message, 0, -2);
</lsl>

Notes

Instead of mouse clicking: "Submit", you can use keyboard keys: press Tab ⇆ and then Enter ↵

See Also

Events

•  listen

Functions

•  llDialog
•  llListen
•  llSay
•  llWhisper
•  llShout
•  llRegionSay

Deep Notes

History

Search JIRA for related Issues

Source

viewer - indra/llcommon/lllslconstants.h <cpp>// llTextBox() magic token string - yes this is a hack. sue me. const std::string TEXTBOX_MAGIC_TOKEN = "!!llTextBox!!";</cpp>

Footnotes

  1. ^ Channel zero is also known as: PUBLIC_CHANNEL, open chat, local chat and public chat

Signature

function void llTextBox( key avatar, string message, integer channel );
<lsl></lsl>