= Set-N-Delete: name2float =
Set the prim text (aka floating text or hover text) to the value of the object's Name field. There are two versions, one really simple and another with a slightly fancier effect.
== Simple ==
Just grab the descrption and set it:
// name2float - Set float text from object name
// self-deleting
default {
state_entry() {
// Set the floating text
llSetText(llGetObjectName(), <1, 1, 1>, 1.0);
// and delete it
llRemoveInventory(llGetScriptName());
}
}
// name2float - Set float text from object name
// self-deleting
// Set to the desired float text, or leave empty to use the object name
// 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 name
FLOAT_TEXT = llGetObjectName();
}
// Set the floating text
llSetText(SplitLine(FLOAT_TEXT, "~"), color, alpha);
// and delete it
llRemoveInventory(llGetScriptName());
}
}
[[:slua:miniscripts:name2float|SLua]]