Script to Add, Change, or Delete Floating Text over Object

Second Life LSL Script to Modify Hovering Text using llSetText with Full Detailed Instructions for Non-Scriptwriters.



This is a simple script for changing the floating text (sometimes called hover text)  above a prim object in Second Life.  The script uses the standard Second Life LSL scripting language function llSetText.



In order to modify, add or delete the floating text you must have modify permission.  This script will fail if you do not have modify permission.  Unfortunately that means you can’t get rid of the annoying floating text above a lot of items you purchase in Second Life, as most of those items will not have modify permission.

The floating text is a property of the prim, not the script.  However a script is used to add, change or delete the floating text.   Because the text is a prim property, once the text is created, it will not change unless a script changes it.  This actually has an advantage, once the floating text is created, the script that created it is no longer necessary.  So the script may be deleted from the prim inventory, which reduces lag.  Because of this, this script automatically deletes itself after it changes the floating text.  That saves you the step of deleting it and assures that it gets deleted.

Because the script deletes itself, it is best to create the script in your inventory rather than in the prim.  Then drag a copy of the script onto your prim, it will quickly change the floating text, and then delete itself.

INSTRUCTIONS:

  1. Open your Second Life Inventory and open the “Scripts” folder.
  2. Right click on the scripts folder and select New Script.  A new script named “New Script” will be created in the folder.  Rename the script, any name will work, for example “Floating Text Changer”.
  3. Right click on the New Script and select “Open”.
  4. Delete the default script code that appears in the editor.
  5. Copy and paste the script code below into the script editor.
  6. Edit the script to insert your text and the text color.  The lines are noted in the script.Replace “Your Product Name\nThis is Floating Text” with the text you want to display.
    Use “\n” to insert a line break in the text. (Notice the backslash in front of the "n".   For no floating text or to remove existing floating text from the prim put a single blank space between the quotes, ie; ” “.  The text MUST be enclosed by quotes (“) and there must be a semi-colon (;) at the end of the line!  The line you edit starts with the word “string” and looks like this: 
        string Floating_Text = “Your Product Name\nThis is Floating Text”;
  7. Edit the script to insert the color of the floating text.  Colors you may use are: white, blue, orange, cyan, pink, green, red, yellow, purple, or black.  The color MUST be enclosed by quotes (“) and there must be a semi-colon (;) at the end of the line!  The color defaults to white if you enter a color the script doesn’t recognize or if you make a typo.  The line you edit starts with the word “string” looks like this:    string Text_Color = “white”;
  8. Save your changes, wait for the “Save Completed” announcement, then close the script edit window.  If an error occurs check for a typo in the lines you edited.  Common errors are not having the text between quotes and accidentally deleting the semi-colon ; at the end of the lines.
  9. Left click on the script, hold the mouse button down, and drag it onto the prim you want the floating text on.   Note: you must have modify permission for the prim to modify the floating text.
  10. The script will modify the floating text. Once the text is set the script is no longer needed.  You’re done! After changing the floating text the script will delete itself from your prim to reduce lag.


CAUTION: Some web browsers remove the backslash before the "n" in the line of the script that says:
string Floating_Text = "Your Product Name\nThis is Floating Text";
 If you copy and paste the script below check for the backslash.

OK, here's the script:




//Script to Add, Change, or Remove Floating Text 
//Copyright by Leaf Illusion
//Please visit my website for scripts, articles and more.
//http://leafillusion.com/

//==========Edit this Section============
//Enter the text you want to display floating above the box between the quote marks below.  n inserts a line break.
//For no floating text or to remove floating text put a single blank space between the quotes, ie; " ".
string Floating_Text = "Your Product Name\nThis is Floating Text";

//Colors: white, blue, orange, cyan, pink, green, red, yellow, purple, black
//On the next line enter the text color you want to use between the quotes.
string Text_Color = "white";

//No need to edit anything below this line
//=========================================
//=========================================
vector ColorCode; // Create variable for color code
default
{
    state_entry()
    {
        Text_Color = llToLower(Text_Color); //Make sure what was entered is all lower case for matching
        if (Text_Color == "blue") ColorCode = <0.0,0.0,1.0>; //Check for each color and assign vector
        else if (Text_Color == "orange") ColorCode = <1.0,0.5,0.0>;
        else if (Text_Color == "cyan") ColorCode = <0.0,1.0,1.0>;
        else if (Text_Color == "pink") ColorCode = <1.0,0.5,0.76>;
        else if (Text_Color ==  "green") ColorCode = <0.0,1.0,0.0>;
        else if (Text_Color == "red") ColorCode = <1.0,0.0,0.0>;
        else if (Text_Color == "yellow") ColorCode = <1.0,1.0,0.1>;
        else if (Text_Color == "purple") ColorCode = <1.0,0.0,1.0>;
        else if (Text_Color == "black") ColorCode = <0.0,0.0,0.0>;
        else ColorCode = <1.0,1.0,1.0>;

        llSetText(Floating_Text,ColorCode, 1.0);
        llSleep(1.0); //Delay to allow all the stuff above to complete
        llRemoveInventory(llGetScriptName());
    }
}

No comments:

Post a Comment