Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Waiting for Dataserver to Finish

Rutherford Beresford
Registered User
Join date: 2 Sep 2007
Posts: 45
05-24-2009 10:05
I've been using the script example from the LSL Wiki that reads values on a note card for various applications for quite some time but can't figure out how to get passed a particular "quirk" and was wondering if someone could offer some advice. I'd post that code here, but I'm getting a weird message when I try to submit my post with the script embedded in it.

Here's a URL to the page that has the script... http://lslwiki.net/lslwiki/wakka.php?wakka=llGetNotecardLine

Let's say that my note card had 10 lines in it and based on the value of gLine I put the value stored in data into one of 10 different global variables. Eight times out of ten if I reference the values of those 10 variables in a piece of code immediately following the state_entry I find that the reading of the note card has not actually finished yet, and that all or most of my variables are empty.

What can I use as a trigger to determine when dataserver has finished reading all the lines of the note card and it's now okay to reference my 10 variables, confident that they will, indeed, have the values from the note card stored in them?

Thank you,
Rutherford
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
05-24-2009 10:29
Change to another state when your reading gets an EOF (End Of File)
By then all lines are read
_____________________
From Studio Dora
Tiziana Catteneo
Registered User
Join date: 19 Feb 2007
Posts: 187
05-24-2009 11:31
Or a state change at the end of dataserver event
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
05-24-2009 11:32
As Dora says it's all down to waiting for the EOF in the dataserver event handler. What you do, how you do it, and when you do it, depends on your application.

// do stuff shows a couple of possibilities:

CODE

string gName;
integer gLine = 0;
key gQueryID;

default {
state_entry() {
gName = llGetInventoryName(INVENTORY_NOTECARD, 0);
gQueryID = llGetNotecardLine(gName, gLine);
llOwnerSay("Reading notecard...");
}

touch_start(integer total_number)
{
if (gLine != -1) llOwnerSay("...wait for it...");
else
{
// do stuff
}
}

dataserver(key query_id, string data) {
if (query_id == gQueryID) {
if (data != EOF)
{
llSay(0, (string)gLine+": "+data);
++gLine;
gQueryID = llGetNotecardLine(gName, gLine);
}
else
{
gLine = -1;
llOwnerSay("...ready!");
// do stuff
}
}
}
}
_____________________
Rutherford Beresford
Registered User
Join date: 2 Sep 2007
Posts: 45
Thank you!
05-24-2009 12:04
So, it sounds like, rather than having "Default" being my main controlling part of the script, I should move that type of thing down to the state that I call at EOF. Great advice. Thank you.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
05-24-2009 13:28
also consider a timer call each time you request a line (so you don't get stuck by data that doesn't show up) and resets in both the timer and on_rez events while you're reading the notecard (in case item goes back to inventory while waiting on a call). just don't forget to stop the timer when you finish reading the notecard...

yeah, seen all those happen.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
05-24-2009 13:31
And/or possibly test the value of a variable that marks whether or not you have finished reading your data or not. Equivalent to the state change. Sometimes more complicated, sometimes less. Depends on the size and complexity of your application.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
05-24-2009 13:40
effectively the same as Pale suggested?
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -