From: Bobby Dayton
I am having tgwo problems. The ideaa is to read the config (3 lines) from a notecard.
I am using llGetNotecardLine along with dataserve. My first problem is that dataserve is also being used for a llRequestAgentData. I believe I have to use a queryid key to tell which call is which.
Your hunch is correct. In order to differentiate between two different function calls that trigger the dataserver event, you must first save the key returned by the function call to a global variable and compare it to the key passed to the dataserver event. If the key in the dataserver event matches the one in the global variable for the function call, then the dataserver data is for that function call.
Here's an example:
key agentDataId;
key notecardDataId;
default {
state_entry() {
agentDataId = llRequestAgentData(llGetOwner(), DATA_BORN);
notecardDataId = llGetNotecardLine("myNote", 0);
}
dataserver(key queryId, string data) {
if (queryId == notecardDataId) {
notecardDataId = ""; // Prevent a bug.
// data contains the first line in myNote.
} else if (queryId == agentDataId) {
agentDataId = ""; // Prevent a bug.
// data contains the date the owner was born.
}
}
}
From: someone
Not quite sure how that goes. But the other part of the problem seems to be reading the card. I wrote a notecard with 3 lines containing Line1 line2 and Line3. I used an example bit of code as follows. Might have an odd typo as I cant get at actual code as I am at work. The output is
Line # 0 : line1
Line # 1 : line1
Line # 2 : line2
Line # 3 : line3
It sometimes counts further. So I am not sure if I have to put some form of EOF caracter on the notecard. But why am I getting the first line twice every time.
Sorry if it's a newby question but I am just getting to grips with LSL...Slowly.
state_entry()
{
lineCounter = 0
dataRequestID = llGetNotecardLine(notecardName, lineCounter);
}
dataserver(key queryid, string data)
{
if (dataRequestID)
{
if (data != EOF)
{
dataRequestID = llGetNotecardLine(notecardName, lineCounter);
lineCounter += 1;
llSay(0, "Line #" + (string)lineCounter + ": " + data);
}
else
{
state default;
}
}
}
Hmm... I cant be sure with the code you posted. It doesnt say what state the script is in, and it calls state default, which is not shown. Keep in mind that when you post a code example it makes it alot easier on replyers when the code actually compiles.

Right now I see two problems with your code. The line "if (dataRequestID)" actually is saying if (dataRequestID != NULL_KEY). dataRequestID will never be NULL_KEY, so this will always evaluate to TRUE.
Also, there's a known bug with the dataserver event where it can erroniously trigger twice with the same data and key. That's why I set my key globals to "" in the previous code, to prevent that.
Here's an example of a reader script that should do what you want:
string notecardName = "myNote";
integer lineCounter = 0;
// Stores query ID of the current call to llGetNotecardLine.
key curNotecardRead;
default {
// ...
}
state readNotecard {
state_entry() {
lineCounter = 0;
curReadId = llGetNotecardLine(notecardName, lineCounter);
}
dataserver(key query, string data) {
if (query == curReadId) { // Then data is for notecard.
curReadId = ""; // Prevent repeat bug.
if (data != EOF) { // This isn't the end of the notecard.
llSay(0, "Line #" + (string)lineCounter + ": " + data);
lineCounter++; // Shorthand for lineCounter += 1;
curReadId = llGetNotecardLine(notecardName, lineCounter);
} else { // Reached end of notecard.
// Do stuff that's supposed to happen after reading the notecard here.
}
}
}
}
Hope this helps!
==Chris