Difference between revisions of "LlSetText"

From Second Life Wiki
Jump to navigation Jump to search
m (changed wording and moved table to make it not overlap the other content on narrow screens)
m
Line 59: Line 59:
</lsl>
</lsl>
By default the floating {{LSLP|text}} will appear on a single line. However, it can be spread over multiple lines by using a line break <code>"\n"</code> (read [[SplitLine]] in section 'See Also').
By default the floating {{LSLP|text}} will appear on a single line. However, it can be spread over multiple lines by using a line break <code>"\n"</code> (read [[SplitLine]] in section 'See Also').
===String escape codes:===
LSL has four [[string]] [[String#Escape_Codes|escape codes]]:
* <code>\n</code> for a new line
* <code>\\</code> for a backslash
* <code>\t</code> for a tab
* <code>\"</code> for a double-quote


===Color & Alpha===
===Color & Alpha===

Revision as of 04:38, 8 January 2014

Summary

Function: llSetText( string text, vector color, float alpha );
0.0 Forced Delay
10.0 Energy

Displays text that hovers over the prim with specific color and translucency (specified with alpha).

• string text floating text to display
• vector color color in RGB <R, G, B> (<0.0, 0.0, 0.0> = black, <1.0, 1.0, 1.0> = white)
• float alpha from 0.0 (clear) to 1.0 (solid) (0.0 <= alpha <= 1.0)

Caveats

  • Do not rely on Floating Text as a storage medium; it is neither secure nor finalized.
    • Floating text has been altered in past server updates, breaking existing content; future changes may occur.
    • Even "invisible"[1] floating text is transmitted to the client.
      • It can be viewed by anyone with a client that is capable of rendering text that is supposed to be invisible.
      • The network packets that contain the text can be sniffed and the text read.
  • If more than one llSetText is called (By reset,interaction or script state) within a prim the latest call will take priority over the previous.
  • text is limited to 254 bytes (compare Limits#Building), if the string is longer it will be truncated to 254 bytes, even if that means the truncation will chop a character in half.
  • An unbroken line of text of a great length may be broken automatically into two lines (one above the other).
  • text can be seen through walls and other object. Be considerate of neighbors in malls and apartment buildings.
    • Visibility distance increases with prim size.
  • Removing the script or deactivating it will not remove a prim's text property. Floating text is not dependent on a script for its continued existence but only when wanting to change it.
  • To remove a prim's text, use the following:

<lsl> // black & transparent

   llSetText("", ZERO_VECTOR, 0);

// same effect as: // llSetText("", <0.0, 0.0, 0.0>, 0.0); </lsl>

  • Vertical whitespace is removed from the end of the text string, so if you want vertical whitespace put any character (like a space) on the last line.
  • Multiple linebreaks with empty lines are converted to a single linebreak, so add a whitespace character on every line you want to skip:

<lsl>

   vector COLOR_WHITE = <1.0, 1.0, 1.0>;
   float  OPAQUE      = 1.0;

// Bad:

   llSetText("Monkeys\n\n\n\n\n", COLOR_WHITE, OPAQUE);

// Good:

   llSetText("Monkeys\n \n \n \n \n ", COLOR_WHITE, OPAQUE);

</lsl>

  • Measurements showed a high impact of process time when doing numerous iterations in a while loop. For approx. 65 thousand iterations the process times are ca. 5 seconds without floating text, 24 seconds with llSetText and 96 seconds when using llSetPrimitiveParams#llSetLinkPrimitiveParamsFast in combination with PRIM_TEXT. Thats why you are not advised to make excessive use of changing a prim's text within such iterations.

Examples

Example of how llSetText could be used to show prim's name in green text: <lsl> default {

   state_entry()
   {
       vector COLOR_GREEN = <0.0, 1.0, 0.0>;
       float  OPAQUE      = 1.0;

// prim's name (not necessarily object's)

       llSetText(llGetObjectName(), <0.0, 1.0, 0.0>, 1.0 );

// delete the script as we only needed it to change the floating text property

       llRemoveInventory(llGetScriptName());
   }

} </lsl> By default the floating text will appear on a single line. However, it can be spread over multiple lines by using a line break "\n" (read SplitLine in section 'See Also').

String escape codes:

LSL has four string escape codes:

  • \n for a new line
  • \\ for a backslash
  • \t for a tab
  • \" for a double-quote

Color & Alpha

Color Code
White <1.0, 1.0, 1.0>
Grey <0.5, 0.5, 0.5>
Black ZERO_VECTOR or <0.0, 0.0, 0.0>
Red <1.0, 0.0, 0.0>
Green <0.0, 1.0, 0.0>
Blue <0.0, 0.0, 1.0>

The x, y & z components of the vector are used to represent red, green, and blue respectively. The range is different from traditional RGB, instead of being 0 -> 255, LSL uses 0 -> 1. <1.0, 1.0, 1.0> represents "white" and <0.0, 0.0, 0.0> represents "black": <lsl> // white & opaque

   llSetText("I am white", <1.0, 1.0, 1.0>, 1.0);

</lsl> <lsl>

   vector myColor;// defaults to ZERO_VECTOR or <0.0, 0.0, 0.0> which is black
   llSetText("I am black and 30% transparent.", myColor, 0.7);
   llSleep(7.5);   // before: <0.0, 0.0, 0.0> black
   myColor.x = 1.0;// now:    <1.0, 0.0, 0.0> red
   llSetText("I am now red and 10% transparent.", myColor, 0.9);

</lsl> If alpha is 1.0 it means the text is fully opaque (alpha), 0.0 would make it completely transparent (invisible): <lsl>

   llSetText("green text with alpha 0.7", <0.0, 1.0, 0.0>, 0.7);
   llSetText("white text with alpha 0.4\n60% transparent", <1.0, 1.0, 1.0>, 0.4);
   llSetText("white text with alpha 1.0\nfully opaque", <1.0, 1.0, 1.0>, 1.0);

// next to lines have the same effect

   llSetText("invisible black text with alpha 0.0\nfully transparent", ZERO_VECTOR, 0);
   llSetText("invisible black text with alpha 0.0\nfully transparent", <0.0, 0.0, 0.0>, 0.0);

</lsl>

Multiple lines

<lsl> // two lines of orange text

   llSetText("I am\non two lines!", <1.0, 0.4, 0.0>, 1.0);
</lsl>

Useful Snippets

Drag this script out of inventory onto an object to erase its set text: <lsl> // http://wiki.secondlife.com/wiki/llSetText

default {

   state_entry()
   {

// remove floating text (empty string & black & 100% transparent)

       llSetText("", ZERO_VECTOR, 0.0);

// delete the script as we only needed it to change the floating text property

       llRemoveInventory(llGetScriptName());
   }

} </lsl> Code to easily specify appearance of hovertext: <lsl> vector blue = <0.0, 0.0, 1.0>; vector orange = <1.0, 0.5, 0.0>; vector cyan = <0.0, 1.0, 1.0>; vector pink = <1.0, 0.5, 0.76>; vector green = <0.0, 1.0, 0.0>; vector red = <1.0, 0.0, 0.0>; vector white = <1.0, 1.0, 1.0>; vector yellow = <1.0, 1.0, 0.1>; vector purple = <1.0, 0.0, 1.0>; vector black = <0.0, 0.0, 0.0>;

string hoverText = "TEXT GOES HERE"; vector hoverColor = white;// set predefined color or any RGB color vector in float form float hoverAlpha = 1.0; // Sets the text's transparency, 1.0 being opaque, while 0.0 would be transparent

default {

   state_entry()
   {
       llSetText(hoverText, hoverColor, hoverAlpha);
   }

} </lsl> To make hovertext under linked prims you can use this simple function: <lsl> mySetLinkText(integer linknum, string text, vector color, float alpha) {

   llSetLinkPrimitiveParamsFast(linknum, [PRIM_TEXT, text, color, alpha]);

}

// For example:

default {

   touch_start(integer total_number)
   {
       mySetLinkText(LINK_SET, "TEST", <0, 1, 0>, 0.5);
   }

} </lsl>

Notes

To actually display text on a prim, see XyzzyText, or consider using parcel prim Media options (useful only if you have control over the land's media settings.)


The function displays text that hover over the prim's center, the prim position. The height over the center is proportional to the prim's Z-dimension exclusively

  • It doesn't matter how the prim is rotated, so if Z is smaller than X and Y the text may be seen on the prim

See Also

Constants

•  PRIM_TEXT

Articles

•  Limits SL limits and constrictions
•  Color in LSL
•  Translucent Color
•  Examples: SplitLine Insert 'new line' escape codes at certain positions of a string
•  Useful snippet: llGetObjectPermMask Label an object with text and newlines to give away or sell

Deep Notes

Footnotes

  1. ^ Floating text with an alpha set to 0.0 is rendered "invisible"

Signature

function void llSetText( string text, vector color, float alpha );