Jump to content
Sign in to follow this  
Cobalt Neutra

need help: looping notecard reader script

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);
 
       
            
            
            }
        }
    }
}

 

 

Share this post


Link to post
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 {

Share this post


Link to post
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);            }        }    }}

 

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thank you! That works great.

Yeah, i was a little leery of the dataserver nonesense, but the person I was trying to riddle this out with swore blind that was the only way it would work.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...