Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

NoteCard Reader Basics - Question

Blaccard Burks
Registered User
Join date: 6 Apr 2007
Posts: 157
06-09-2007 18:37
Here goes,

I'm trying to create a simple notcard reader script that interpets data in the notecard...

The notecard data is as follows. The vector will be used to set color of text and the other 2 lines some integer functions. The other integers used are called "limit" and "offset". My questions is how to I store the rest of the data to be used in this script or another script.

Thanks,

Blaccard Burks


Notecard settings

<1.0,1.0,0.0>
200
10

_________________

The Basic Script:

-----start code -----

vector nColor;
integer limit;
integer offset;
key kQuery;

default {
on_rez(integer param)
{
llResetScript();
}
state_entry() {
llSay(0, "Reading notecard...";);
kQuery = llGetNotecardLine("config", 0);
// kQuery = llGetNotecardLine("config", 1); don't know what to do here...
// kQuery = llGetNotecardLine("config", 2);
}

dataserver(key query_id, string sdata)
{

llSay(0, sdata);
nColor = (vector)sdata;
llSetText("This is a test", nColor, 1);

}
}

_____ end code_____
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
06-09-2007 18:56
There's more than one way, but for example, after you read line 0 in the state entry, it will trigger the dataserver event. There, you could put the read of line 1 in the dataserver event at the end. Which will trigger the data server event again, and then you read line 2, etc.

So you'd need a variable, say LineNumber, that you would continue to increment for your next call to llGetNotecardLine. And at the beginning of the dataserver event, check what the value of LineNumber is, which would tell you what line you just read, and how to parse it.
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
06-10-2007 06:52
Here you go...this will allow you to add more lines (the contents are keyed to the line number, not the most robust way to do it, but it works.).

Many note scripts increment the line number after the request call, but I prefer to increment the line number before sending to the request, that way when the data comes in, noteline contains my *current* line number.

Just be aware that your state_entry code will have to be finished before the dataserver event will return with the first line of data, so you'll have to finish your startup process from within the last dataserver call, when the notecard has returned EOF. (See where I wrote "// carry on with the script".)

CODE

vector nColor;
integer limit;
integer offset;

string notename = "config";
integer noteline;
key kQuery;

default {
on_rez(integer param)
{
llResetScript();
}

state_entry()
{
llOwnerSay("Reading notecard...");
noteline = 0;
kQuery = llGetNotecardLine(notename, noteline);
}

dataserver(key query_id, string sdata)
{
if (query_id != kQuery) // if it's not what we requested
return; // ignore invalid data

if (sdata == EOF) // if we are at end of notecard
{
llOwnerSay("Note Reading Done.");
// carry on with starting up
return;
}

// if we get to here, we have note data to handle

llOwnerSay(sdata); // debug - announce what was read

if (noteline == 0) // we just read line 0
nColor = (vector)sdata;

if (noteline == 1) // we just read line 1
limit = (integer)sdata;

if (noteline == 2) // we just read line 2
offset = (integer)sdata;

noteline += 1;
kQuery = llGetNotecardLine(notename, noteline); // get next line
}
}

Blaccard Burks
Registered User
Join date: 6 Apr 2007
Posts: 157
06-10-2007 11:03
Thanks Boss.

This was kinda what I had in mind. I'm starting to understand when events begin and end. I've gotten far with the basics, now I assume that after the reading event is done I'd call another event to process the data.


Thanks a bunch.