Jump to content

Script doesn't wait for functions to return


Rhiannon Arkin
 Share

You are about to reply to a thread that has been inactive for 2672 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi

I have a funny issue with one of my scripts. thought i could ask here, it might be a simple issue. 

in my touch_start I call for a notecard reader. now the script should wait until the notecard reader returns the desired value. 

but it doesn't.

it just moves on and the card reader returns the values too late it seems. I know that because i have some llOwnerSay inside the reader so i can see where it is. 

It all works, except that the return from the reader is too late, the script doesn't wait for it. I tried some llSleeps but they didn't help. 

any idea how i can make the script wait for it?

    touch_start(integer total_number)
    {
        key    id   = llDetectedKey(0);
        string name = llDetectedName(0);

        init(card); //initialize notecard reader <--THIS READS THE NC

        llWhisper(0,question +"\n\n\n"); <--- THIS DOESN'T WAIT
        listenhandle=llListen(0,"",id,"");
        llSetTimerEvent(gap);
    }

thanks in advance!

R.

 

Link to comment
Share on other sites

Notecard operations are "asynchronous"; the code will not wait, as the "read response" occurs in an event.   The reader function would have to call llGetNotecardLine(), which will trigger a dataserver() event response.  You would have to have your dataserver() event call another function after it gets the notecard line to continue processing.

 

Link to comment
Share on other sites

 

Ok, here's an example (this is pseudo-code not real code).

key NotecardQueryID="";  // Will be used if reading from Notecard via llGetNotecardLine

handlenotecardresponse(string message) {

  llWhisper(0,question +"\n\n\n");  
  listenhandle=llListen(0,"",id,""); // Note that you will need to add code for the listen() event for handling any responses to this
  llSetTimerEvent(gap);  // Note that you will need to add code for the timer() event

}

 

default {

touch_start(integer total_number) {

  NotecardQueryID=llGetNotecardLine("NotecardName", 1); // Get first notecard line, save query id!!

// Don't bother doing else in this function, we need to wait for the notecard

  } // end touch_start

 

dataserver(key queryid, string data) {

if (querid==NotecardQuerID) { // Yes! We got a notecard line back!

 handlenotecardresponse(data);

 }

} // end dataserver

 

}

Link to comment
Share on other sites

I am not yet succeeding in what you try to do here. This dataserver thing is a bit enigmatic to me. Maybe i need to load all notecards in the state entry so they are loaded when i get to the touch event. i'll play some more. but it's not really logic to me yet. 

thanks for your help 

R.

 

 

Link to comment
Share on other sites

unless you have a mutherhuge notecard, most people read the notecard

into a list when the script starts....

 

key query_id;integer count;string Curr;key kQuery;list choices;init(){  Curr =  llGetInventoryName(INVENTORY_NOTECARD,0);    kQuery = llGetNotecardLine(Curr, count); // start the notecard reading loop in the dataserver}default{    state_entry()    { init();    }     on_rez()    { init();    }    touch_start(integer total_number)    {        key    id   = llDetectedKey(0);        string name = llDetectedName(0);        llWhisper(0,question +"\n\n\n"); //<--- choices list is populated, get "question" there?        listenhandle=llListen(0,"",id,"");        llSetTimerEvent(gap);    }    dataserver(key query_id, string data)  // // fill the list by reading the notecard    {   if (query_id == kQuery)        {                          if (data == EOF)             {  count = 0;               llOwnerSay("DONE");              // llOwnerSay("NC info : \n" + llDumpList2String(choices,"\n"));            }            else             {  choices += (string)data;                  ++count;                      kQuery = llGetNotecardLine(Curr, count);               }        }     }     changed(integer change)     {        if (change & CHANGED_INVENTORY)                 { llOwnerSay("The inventory has changed.");          llResetScript();        }    }}
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2672 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...