LlGetNotecardLine - Second Life Wiki

LlGetNotecardLine

From Second Life Wiki

(Redirected from LSL llGetNotecardLine)
Jump to: navigation, search

Contents

Description

Function: key llGetNotecardLine( string name, integer line );
217 Function ID
0.1 Delay
10.0 Energy

Requests the line line of the notecard name from the dataserver.

Returns a key that is the handle for a dataserver event response.

• string name a notecard in the prim's inventory or UUID
• integer line Line number in a notecard (the index starts at zero).


line does not support negative indexes.
If line is past the end of the notecard EOF is returned by the dataserver.

Caveats

  • This function causes the script to sleep for 0.1 seconds.
  • If name is missing from the prim's inventory and it is not a UUID or it is not a notecard then an error is shouted on DEBUG_CHANNEL.
  • If name is a UUID then there are no new asset permissions consequences for the object.
    • The resulting object develops no new usage restrictions that might have occurred if the asset had been placed in the prims inventory.
  • If notecard contains embedded inventory items (such as textures and landmarks), EOF will be returned, regardless of the line requested.
  • If the requested line is longer then 255 bytes the dataserver will return the first 255 bytes of the line.
  • If the notecard is empty, the dataserver will shout on the DEBUG_CHANNEL that the notecard does not exist. This is because until a notecard is saved for the first time, it does not exist as an asset only as an inventory placeholder (llGetInventoryKey will return NULL_KEY).

Examples

 
key kQuery;
integer iLine = 0;
default {
 
    state_entry() {
        llSay(0, "Reading notecard...");
        kQuery = llGetNotecardLine("My Notecard", iLine);   // read in "My Notecard" when you can
    }
 
    dataserver(key query_id, string data) {
 
        if (query_id == kQuery) {    // were we called to work on "My Notecard"?
            // 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, "Line " + (string)iLine + ": " + data);   // data has the current line from this notecard
 
                //request next line
                iLine++;
                kQuery = llGetNotecardLine("My Notecard", iLine);   // read another line when you can
 
            }
        }
    }
}
 

Useful Snippets

 
/////
//  Generic Multi Notecard reader by Brangus Weir
//  Given freely and published on wiki.secondlife.com
//
//  This script will read three note cards and store the results into three lists.
//  It can be modified and extended to as many (or few) cards as you'd like to read. 
//
 
list gOneCard;    // All the lines from from the first card
list gTwoCard;    // All the lines from from the second card
list gThreeCard;  // All the lines from from the third card
 
string gsCardOneName = "One";  //Set these to the name of the invetory item.
string gsCardTwoName = "Two";
string gsCardThreeName = "Three";
 
//Temporary variables for processing
string g_sNoteCardName; // Name of the card to be read.
list g_lTempLines;      // The resulting data pushed into a list
integer g_iLine;        // The line count for the card reader
key g_kQuery;           // The key of the card being read
 
 
initialize(string _action) {
    // Due to the execution order when using dataserver, this function sets the first card to 
    // be read, and the excetuion finishes when called again with the _action set to "finish".
    if (_action == "") {
        loadNoteCard(gsCardOneName);
    } else if (_action == "finish") {
        // All cards have been read into the lists... now you can do any kind of string
        // manipulations to get the data you need to set your script.
        // But here we will prove that the cards have been read with a loop
 
        integer end = llGetListLength(gOneCard);  //Always evaluate this once, don't do it
                                                  //INSIDE the for loop like noob programers will.
                                                  //Reduce lag, THINK ABOUT MACHINE CYCLES!
        integer i = 0;
        for (; i< end; ++i)
            llSay(0, llList2String(gOneCard,i));
        end = llGetListLength(gTwoCard);
        for (i = 0; i< end; ++i)
            llSay(0, llList2String(gTwoCard,i));
        end = llGetListLength(gThreeCard);
        for (i = 0; i< end; ++i)
            llSay(0, llList2String(gThreeCard,i));
    }                
 
}
 
loadNoteCard( string _notecard ) {
    g_lTempLines = []; //clear the temp lines
    g_sNoteCardName = _notecard;
    g_iLine = 0;
    g_kQuery = llGetNotecardLine(g_sNoteCardName, g_iLine);  
 
}
 
notecardFinished(string _notecard){
    // Called at the end of each notecard as it is read. The temp results are stored
    // and the next card is commanded to be read.
    if (_notecard == gsCardOneName) {
        gOneCard = g_lTempLines;
        loadNoteCard(gsCardTwoName);
    } else if (_notecard == gsCardTwoName) {
        gTwoCard = g_lTempLines;
        loadNoteCard(gsCardThreeName);
    } else if (_notecard == gsCardThreeName) {
        gThreeCard = g_lTempLines;
        initialize("finish");  // Finally pass exection to finish the initialization.   
    }    
}
 
default
{
    state_entry()
    {
    }
 
    touch_start(integer _num_det){
        initialize("");     
 
    }
 
    dataserver(key _query_id, string _data) 
    {
        if (_query_id == g_kQuery) {
            // this is a line of our notecard
            if (_data != EOF) {    
                // increment line count
                g_lTempLines += [_data];
                //request a next line
                g_iLine++;
                g_kQuery = llGetNotecardLine(g_sNoteCardName, g_iLine);
            } else {
             //The notecard has been read 
             //notify end of read
             notecardFinished(g_sNoteCardName);   
 
            }
        }
    }
}
 

See Also

Events

•  dataserver

Functions

•  llGetNumberOfNotecardLines