You are currently browsing the tag archive for the ‘output’ tag.

In my previous blog entry about creating a HUD, I briefly mentioned that it was possible, but not necessarily easy, to have dynamic output on a HUD.

Here is a relatively simple way of doing this, along with a script that makes use of the technique. It relies on three simple facts relating to the floating text that can appear above a prim. First, this text still appears even when the prim is used in a HUD; second, it is then only visible to the wearer; and finally, the floating text can have multiple lines. We can use this to create a screen display for the HUD.

As an example, let’s create a ‘green-screen’ monitor for a HUD. Create a basic HUD window (a simple block prim), and add two more prims, one directly above the other. The upper prim will provide the background, the lower prim will generate the text.

Set the upper prim’s color to black, and size it to something suitable (the actual size depends on the number of lines of text you will be displaying, so some trial and error is probably required). Link the prims, and attach the result as a HUD. See my previous article if you need more details about creating a HUD.

Now we need a script to generate our dynamic text. The following script implements a scrolling display, and adds a line to the display every time the owner clicks the text prim (just as a demonstration). Create a new script in the lower prim, and copy the script into it, replacing the default script.

The result should look something like this:

integer linePos = 0;
list lines;
integer listLength;
vector textColor = ; // Green
init()
{
    clear();
}
clear()
{
    lines   = ["", "", "", "", ""];
    listLength = llGetListLength(lines);
    linePos = 0;
    updateDisplay();
}
setLine(integer lineNo, string lineText)
{
    // If the requested line number is past the end of
    // the list of lines, scroll the lines.
    if (lineNo > listLength)
    {
        lines = llList2List(lines, 1, listLength - 1);
        lines += "";
        lineNo = listLength - 1;
    }
    lines = llListReplaceList(lines, [lineText], lineNo, lineNo);
    updateDisplay();
}
updateDisplay()
{
    string output;
    integer i;
    integer count = listLength;
    for (i = 0; i < count; i++)
    {
        output += llList2String(lines, i) + "\n";
    }
    llSetText(output, textColor, 1.0);
}
addLine(string lineText)
{
    setLine(linePos, lineText);
    if (linePos < listLength)
      linePos++;
}
default
{
    state_entry()
    {
        init();
    }
    touch_start(integer count)
    {
        // This is just a dummy example of how to update
        // the display. When the owner touches the prim
        // we will add a message to the display. We'll
        // check that it was the owner who touched us,
        // although that isn't really necessary if this
        // is in a HUD. 
        if (llDetectedKey(0) == llGetOwner())
        {
            addLine("Touched at " + llGetTime());
        }
    }
    on_rez(integer param)
    {
        init();
    }
}