Note Card Loop Example

I was helping a friend out with a simple request. He wanted a prim to change it’s hover text to display messages from a note card. Once you reach the end of the note card, it needed to start from the beginning again. It took about 10 minutes, but i came up with a pretty strait forward example of how it can be done.

integer noteCardLine;
integer noteCardCount;
string noteCardName;
key noteCardCountRequestId;
key noteCardLineRequestId;

init()
{
// reset to read first line
noteCardLine = 0;

// find the note card name
noteCardName = llGetInventoryName(INVENTORY_NOTECARD, 0);

// if note card is missing
if(noteCardName == “”)
{
// notify owner
llOwnerSay(“I don’t have a note card to read!”);
}

// count number of lines in note card
noteCardCountRequestId = llGetNumberOfNotecardLines(noteCardName);
}

default
{
state_entry()
{
init();
}

on_rez(integer start_param)
{
init();
}

changed(integer change)
{
// did note card change?
if(change & CHANGED_INVENTORY)
{
// initialize again
init();
}
}

touch_start(integer total_number)
{
// no note card?
if(noteCardName == “”)
{
// do nothing
return;
}

// empty note card?
if(noteCardCount == 0)
{
// do nothing
return;
}

// if already past end of available note card lines
if(noteCardLine >= noteCardCount)
{
// reset to read first note card line
noteCardLine = 0;
}

// read the next line (and incriment to next line)
noteCardLineRequestId = llGetNotecardLine(noteCardName, noteCardLine++);
}

dataserver(key queryid, string data)
{
if(queryid == noteCardLineRequestId)
{
// if no more lines
if(data == EOF)
{
// note card count changed? reinitialize
init();
}
else
{
// we have something from the note card!

// display the text
llSetText(data, <1, 1, 1>, 1);
}
}

// got feedback for the number of lines in the note card?
if(queryid == noteCardCountRequestId)
{
// save number of lines
noteCardCount = (integer)data;

// no lines?
if(noteCardCount == 0)
{
// notify owner of problem
llOwnerSay(“Hey, this note card is empty”);
}
else
{
// request first line
noteCardLineRequestId = llGetNotecardLine(noteCardName, noteCardLine++);
}
}
}
}

posted by Dedric Mauriac on Nowhereville using a blogHUD : [blogHUD permalink]

2 Responses to Note Card Loop Example

  1. I think you need to add a inside that llSetText instruction.
    Also, you may want to explicitely add in your blog post that the text will change when you touch the prim.

    I just tried this script and (after adding text color) it indeed works fine.
    Thanks!

%d bloggers like this: