Dylan Rickenbacker
Animator
Join date: 11 Oct 2006
Posts: 365
|
09-03-2009 10:27
I think I'm going blind here. In the script below, the readout() function is being called, but the respective query never arrives at the dataserver event. Can someone help me see why not? Thanks! string gName; key gQueryID; integer gLine; key gLength; integer gLengthInt;
readout() { gQueryID = llGetNotecardLine(gName, gLine); }
default { state_entry() { gName = "medialist"; llListen(29,"",NULL_KEY,""); }
listen(integer channel,string name,key id,string msg) { if(msg == "playlist") { gLength = llGetNumberOfNotecardLines(gName); } } dataserver(key query, string data) { if(query == gLength) { gLengthInt = (integer)data; for(gLine = 0;gLine < gLengthInt; gLine++) { readout(); } }
if(query == gQueryID) { llSay(0,"Receiving query for line #" + (string)gLine); list elements = llParseString2List(data, ["|",":"], []); llSay(0,llList2String(elements,0)); llRegionSay(39,llList2String(elements,0)); } } }
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
09-03-2009 11:08
You call readout() gLengthInt times within the dataserver event and you have only one gQueryID. If you are lucky you will read the last note card line and nothing else.
_____________________
From Studio Dora
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
09-03-2009 11:11
You execute a loop as soon as you get the 'dataserver' event for the notecard's size. But each time through the loop the gQueryID gets assigned a new request key, without there ever being a chance to receive the 'dataserver' event for the previous key(s). That's because scripts are essentially single-threaded; none of the other 'dataserver' events can be serviced until your loop exits and you return from the first (length-retrieving) one. On the other hand, I'm not sure why you aren't getting the 'dataserver' event for the LAST query you do. I think that one should arrive, but by then gLine would also equal gLengthInt. Hmm. EDIT: Oops. You beat me to it while I was writing my long response Dora. Anyway, agreed. 
|
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
|
09-03-2009 11:21
You can't use a For-Loop and expect to receive events (it violates the nature of Event Driven program logic). You are, in effect, stuck inside the datasever event handler until the loop has completed, by which time your qQueryId is past its Sell By Date. Instead you need to use the dataserbver event itself to control the loop. string gName; key gQueryID; integer gLine;
readout() { gQueryID = llGetNotecardLine(gName, gLine); }
default { state_entry() { gName = "medialist"; llListen(29,"",NULL_KEY,""); }
listen(integer channel,string name,key id,string msg) { if(msg == "playlist") { gLine = 0; readout(); } } dataserver(key query, string data) { if(query == gQueryID) { if(data != EOF) { llOwnerSay("Receiving query for line #" + (string)gLine); list elements = llParseString2List(data, ["|",":"], []); llOwnerSay(llList2String(elements,0)); llRegionSay(39,llList2String(elements,0));
++gLine; readout(); } else llOwnerSay("Done."); } } }
|
Dylan Rickenbacker
Animator
Join date: 11 Oct 2006
Posts: 365
|
09-03-2009 11:41
Brilliant! Thanks! 
|