LSL Scripts: Scrolling floating text

This is one of an occasional series of small but (I hope) useful pieces of code.

Floating text above a prim has a lot of uses in Second Life, and here is a script which might add even more possibilities. This takes advantage of the fact that you can display multiple lines of text and uses this to create a scrolling text display, like so:

It works very simply. We have a list which stores the lines to be displayed. To add a new line to the text, and to scroll the text up, we remove the first entry in the list, and add the new entry at the end. To display the text, we just string the entries in the list together, separating them with a new-line, and set the result as the floating-text for the prim.

In this little example program, a line of text is added whenever the prim is touched.

[cpp]
list lines = ["", "", "", "", ""];
addLine(string line)
{
// Add the new message to the end of the list, losing the first entry
// from the list at the same time.
lines = llList2List(lines, 1, llGetListLength(lines) – 1) + [line];
// Concatenate the lines together, separated by a new-line.
string output = llDumpList2String(lines, "\n");
// Set the result as the floating text.
llSetText(output, , 1.0);
}
default
{
touch_start(integer count)
{
addLine("Touched at " + llGetTimestamp());
}
}
[/cpp]


Posted

in

, , ,

by

Comments

Leave a Reply