Jump to content

need help: looping notecard reader script


Cobalt Neutra
 Share

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

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

Recommended Posts

I'm trying to write a script that reads lines of text from a notecard into chat, and when it gets to the last line, loops back to the first line, so it ends up in a repeating loop until acted upon by an outside command.

 

So far I've managed to get a script together that reads the text, but I cannot find any way to make it loop.

 

key kQuery;
integer iLine = 0;
string thenote = "New Note";
default {
 
    state_entry() {

    }
        link_message(integer send, integer num, string message, key id)
    {
        if (message == "Sitting")
        {

        kQuery = llGetNotecardLine(thenote, iLine);
                }
               if (message == "Standing")
     {
         
        kQuery = llGetNotecardLine(thenote, 9999);
        
        iLine = 0;
        
        }
    }

 
    dataserver(key query_id, string data) {
 
        if (query_id == kQuery) {
            // this is a line of our notecard
           
            if (data == EOF) {    
 
             llSay(0, "No more lines in notecard, read " + (string)iLine + " lines.");
 
            } else {
 
                // increment line count
                llSay(0, data);
                
                // delay time between responses
                llSleep(5.0);
 
 
                //request next line
                ++iLine;
                kQuery = llGetNotecardLine(thenote, iLine);
 
       
            
            
            }
        }
    }
}

 

 

Link to comment
Share on other sites

oh someone will beat me for this... I just know it....

here's the absolute worst (but simplest) way to do it.....

if (data == EOF) {
llSay(0, "No more lines in notecard, read " + (string)iLine + " lines.");
kQuery = llGetNotecardLine( thenote, iLine = 0);
} else {
Link to comment
Share on other sites

LOL, we need to do even worse, because the script used a forced EOF with the "Standing" message =D

Cobalt, maybe you can read the notecard into a list and loop through that on a timer, so that you can run away from this dataserver torture?

 

 

key kQuery;integer iLine = 0;string thenote = "New Note";string gSitMessage = ""; // to decide if reading should continue, instead of forced EOFdefault{     link_message(integer send, integer num, string message, key id)    {        gSitMessage = message; // save the value so the dataserver event can see it        if (message == "Sitting")        {            kQuery = llGetNotecardLine(thenote, iLine);        }        if (message == "Standing")        {            // line number does not really matter because gSitMessage check will intercept            kQuery = llGetNotecardLine(thenote, 0);        }    }    dataserver(key query_id, string data)    {        if (query_id == kQuery)        {            // check if "Standing", quit reading if yes            if (gSitMessage == "Standing")            {                iLine = 0; // reset vounter                llSay(0, "Stood, quit reading");            }            else if (data == EOF)            {                // at end of notecard, so restart from the top                iLine = 0;                kQuery = llGetNotecardLine(thenote, iLine);             }            else            {                // increment line count                llSay(0, data);                                // delay time between responses                llSleep(1.0);                 //request next line                ++iLine;                kQuery = llGetNotecardLine(thenote, iLine);            }        }    }}

 

 

Link to comment
Share on other sites

Void pointed you in the right direction... Here is the full script.

I assumed the messages "Sitting" and "Standing" are the triggers to start/stop reading.

 

key kQuery;integer iLine = 0;string thenote = "New Note";integer doREAD = FALSE;default{    link_message(integer sender, integer num, string msg, key id)    {        if (msg == "Sitting")        {            iLine = 0; // Read from the beginning            doREAD = TRUE; // Reading allowed            kQuery = llGetNotecardLine(thenote, iLine);        }        else if (msg == "Standing")        {            doREAD = FALSE; // Stop reading        }    }    dataserver(key query_id, string data)    {        if (query_id == kQuery)        {            if (data == EOF)            {                    if (doREAD) // Don't restart unless allowed                {                    iLine = 0;                    kQuery = llGetNotecardLine(thenote, iLine);                }            }            else if (doREAD) // Don't go on unless allowed            {                llSay(0, data);                llSleep(5.0);                ++iLine;                kQuery = llGetNotecardLine(thenote, iLine);            }        }    }}

 If there is no typo, that should work...

 

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...
You are about to reply to a thread that has been inactive for 4759 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...