Difference between revisions of "LlTextBox"

From Second Life Wiki
Jump to navigation Jump to search
m
m
 
(32 intermediate revisions by 11 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|inject-2={{LSL_Function/avatar|avatar}}{{LSL_Function/chat|chat_channel}}
|inject-2=
{{LSL_Function/avatar|avatar|region=*}}
{{LSL_Function/chat|channel|message|dialog=text box}}
|func_id=335|func_sleep=1.0|func_energy=10.0
|func_id=335|func_sleep=1.0|func_energy=10.0
|func=llTextBox
|func=llTextBox
|p1_type=key|p1_name=avatar|p1_desc
|p1_type=key|p1_name=avatar
|p2_type=string|p2_name=message|p2_desc=message to be displayed in the text box
|p2_type=string|p2_name=message
|p3_type=integer|p3_name=chat_channel|p3_desc
|p3_type=integer|p3_name=channel
|return_type
|return_type
|return_text
|return_text
|func_desc=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 [[llSay|said]] on '''chat_channel''' when the "OK" button is clicked.
|func_desc=Shows a dialog box on {{LSLP|avatar}}'s screen with the text {{LSLP|message}}. It contains a text box for input, any text that is entered is [[llSay|said]] by {{LSLP|avatar}} on {{LSLP|channel}} when the "Submit" button is clicked.
|func_footnote
|func_footnote
|caveats=* Not supported in official Linden Labs viewers prior to version 2.4, and some [[Third_Party_Viewer_Directory|TPVs]] may not support it. Unsupported viewers will display a dialog box with a single option of "!!llTextBox!!".
|caveats=* Not supported in official Linden Lab viewers prior to version 2.4, and some [[Third_Party_Viewer_Directory|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 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).
* 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 "OK" button is pressed, it will not be able to hear the response.
* 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.  
** 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===
===message limits===
*If it exceeds 8 lines a scroll bar will appear.
*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]].
*{{LSLP|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 <source lang="lsl2">llTextBox(avatar_key," \n",dialog_channel);</source>


|examples=<lsl>integer listener;
|notes=
Instead of mouse clicking: "Submit", you can use keyboard keys: press {{K|Tab}} and then {{K|Enter}}


|examples=
<source lang="lsl2">
integer  gListener;
default
default
{
{
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
         llListenRemove(listener);//A previous user may not have responded. Make sure we don't leak!
         // See 'discussion' page for more comments on choosing a channel and possible left-open listener
         integer channel = ~(integer)llFrand(1000.0);
         integer channel = -13572468;
         listener = llListen(channel,"","","");
         // "" saves byte-code over NULL_KEY
         llTextBox(llDetectedKey(0),"Write something here...",channel);
        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)
     listen(integer channel, string name, key id, string message)
     {
     {
         llSay(0,"You wrote: " + message);
        llListenRemove(gListener);
        llListenRemove(listener);
         llSay(0, "You wrote: " + message);
     }
     }
}</lsl>
}
</source>
If the user hits {{K|Enter}} before clicking the <code>"Submit"</code> 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:
<source lang="lsl2">
        message = llStringTrim(message,STRING_TRIM);
</source>
 
|spec
|spec
|constants
|constants
Line 53: Line 66:
|notes
|notes
|location=
|location=
{{SourceLink|indra/llcommon/lllslconstants.h|line=189}}
{{SourceLink|viewer|indra/llcommon/lllslconstants.h|line=189}}
<cpp>// llTextBox() magic token string - yes this is a hack.  sue me.
<cpp>// llTextBox() magic token string - yes this is a hack.  sue me.
const std::string TEXTBOX_MAGIC_TOKEN = "!!llTextBox!!";</cpp>
const std::string TEXTBOX_MAGIC_TOKEN = "!!llTextBox!!";</cpp>
Line 62: Line 75:
|cat4
|cat4
}}
}}
<div style="display:none"><lsl></lsl></div>

Latest revision as of 14:24, 17 November 2022

Summary

Function: llTextBox( key avatar, string message, integer channel );
1.0 Forced Delay
10.0 Energy

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
    llTextBox(avatar_key," \n",dialog_channel);
    

Examples

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);
    }
}

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:

        message = llStringTrim(message,STRING_TRIM);

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

Source

indra/llcommon/lllslconstants.h - viewer <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 );