Table of Contents

Set-N-Delete: desc2float

Set the prim text (aka floating text or hover text) to the value of the object's Description field. There are two versions, one really simple and another with a slightly fancier effect.

Simple

Just grab the descrption and set it:

desc2float-simple.lsl
// desc2float - Set float text from object description
// self-deleting
 
default {
    state_entry() {
        // Set the floating text
        llSetText(llGetObjectDesc(), <1, 1, 1>, 1.0);
 
        // and delete it
        llRemoveInventory(llGetScriptName());
    }
}

Fancy

desc2float-fancy.lsl
// desc2float - Set float text from object description
// self-deleting
 
// Set to the desired float text, or leave empty to use the object description
// Use '~' to insert a newline
string FLOAT_TEXT = "";
 
vector color = <1, 1, 1>;
float alpha = 1.0;
 
// Based on SplitLine() from http://wiki.secondlife.com/wiki/SplitLine
string SplitLine(string _source, string _separator) {
    integer offset = 0;
    integer separatorLen = llStringLength(_separator);
    integer split = -1;
 
    do {
        split = llSubStringIndex(llGetSubString(_source, offset, -1), _separator);
        llOwnerSay("split="+(string)split+": "+_source);
        if (split != -1) {
            _source = llGetSubString(_source, 0, offset + split - 1) + "\n" + llGetSubString(_source, offset + split + separatorLen, -1);
            offset += split + separatorLen;
        }
    } while (split != -1);
    return _source;    
}
 
default {
    state_entry() {
        if (FLOAT_TEXT == "") {
            // get description
            FLOAT_TEXT = llGetObjectDesc();
        }
 
        // Set the floating text
        llSetText(SplitLine(FLOAT_TEXT, "~"), color, alpha);
 
        // and delete it
        llRemoveInventory(llGetScriptName());
    }
}

SLua