Difference between revisions of "LlGetNotecardLineSync"

From Second Life Wiki
Jump to navigation Jump to search
m (Replaced llSay() with llOwnerSay(), else, when users read a long notecard they risk hitting the region anti-spam throttle and having their own chat and their objects' chat blocked until region restart.)
m (added a comment to explain the presence of the return in the for/next loop.)
 
(10 intermediate revisions by 6 users not shown)
Line 7: Line 7:
|p1_type=string|p1_name=name
|p1_type=string|p1_name=name
|p2_type=integer|p2_name=line|p2_desc=Line number in a notecard (the index starts at zero).
|p2_type=integer|p2_name=line|p2_desc=Line number in a notecard (the index starts at zero).
|func_desc=Requests the line {{LSLP|line}} of the notecard {{LSLP|name}} from the dataserver.
|func_desc=Gets the {{LSLP|line}} of the notecard {{LSLP|name}} from the region's notecard cache immediately without raising a dataserver event.
|Return_text=containing the text of the requested line from the notecard.
|Return_text=containing the text of the requested line from the notecard.
|func_footnote=If {{LSLP|line}} is past the end of the notecard [[EOF]] is returned by the [[dataserver]].
|func_footnote=Returns [[EOF]] if {{LSLP|line}} is past the end of the notecard.
|spec=
|spec=
This function returns a string containing the requested line from a notecard in prim inventory, without the need for an asynchronous dataserver event, if the notecard is cached/known in its entirety by the simulator. This speeds up acessing notecard lines tremendously, and allows for near instantaneous random access.
This function returns a string containing the requested line from a notecard in prim inventory, without the need for an asynchronous dataserver event, if the notecard is cached/known in its entirety by the simulator. This speeds up acessing notecard lines tremendously, and allows for near instantaneous random access.
Line 15: Line 15:
If the notecard does not exist it returns the constant [[NAK]] and will shout a message to the debug channel.  If the notecard has not been previously cached on the simulator it will return the [[NAK]] constant.
If the notecard does not exist it returns the constant [[NAK]] and will shout a message to the debug channel.  If the notecard has not been previously cached on the simulator it will return the [[NAK]] constant.


It is not safe to assume a notecard has been previously cached. Data for a previously cached notecard may be dropped from the cache at any time, especially on a busy server.
Notecards are cached into a fixed-size buffer, with the oldest (least-recently read) notecard getting removed first. It is not safe to assume a notecard has been previously cached. Data for a previously cached notecard may be dropped from the cache at any time, especially on a busy server.


|caveats=* If notecard contains embedded inventory items (such as textures and landmarks), [[EOF]] will be returned, regardless of the line requested.
|caveats=* 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 than 1024 bytes the returned string will be truncated to the first 1024 bytes of the line.
*If the requested line is longer than 1024 bytes the returned string will be truncated to the first 1024 bytes of the line.
*A dataserver event does '''not''' get raised. Therefore, other scripts in the linkset are unaware of the processed notecard lines.
|constants
|constants
|examples=
|examples=
Line 40: Line 41:
             integer index;
             integer index;
              
              
             for (index = 0; index < count; ++index)
             for (index = 0; index < (count+1); ++index)
             {
             {
                 string line = llGetNotecardLineSync(NOTECARD_NAME, index);
                 string line = llGetNotecardLineSync(NOTECARD_NAME, index);
Line 55: Line 56:
                     llOwnerSay(line);
                     llOwnerSay(line);
                 }
                 }
            }
        }
    }
}
</syntaxhighlight>
Following example to call a normal [[dataserver]] notecard read using [[llGetNotecardLine]] if llGetNotecardlineSync fails with a NAK.  Keep in mind to clear any lists you are reading data into when using the following example to keep from corrupting the integrity of the list data.
<syntaxhighlight lang="lsl2">
// llGetNotecardLineSync example with fall back to the old dataserver read
// if llGetNotecardLineSync fails with a NAK.
string  NOTECARD_NAME = "notecard";
key    READ_KEY = NULL_KEY;
key    noteCard_qry;
integer noteCard_line;
default
{
    state_entry()
    {
        // read the notecards number of lines to the
        // simulators cache memory
        READ_KEY = llGetNumberOfNotecardLines(NOTECARD_NAME);
    }
   
    dataserver(key request, string data)
    {
        // read notecards using the new llGetNotecardLineSync function
        // from simulator cache.
        if (request == READ_KEY)
        {
            integer count = (integer)data;
            integer index;
           
            for (index = 0; index < (count+1); ++index)
            {
                string line = llGetNotecardLineSync(NOTECARD_NAME, index);
                if (line == NAK)
                {
                    // Got a notecard NAK meaning llGetNotecardLineSync had and error.
                    // falling back to the old dataserver event to read notecards.
                    llOwnerSay("---NAK---");
                    noteCard_qry = llGetNotecardLine(NOTECARD_NAME, noteCard_line);
                    return;  // return is needed to break the for/next loop once the NAK is encountered.
                }
                else if (line == EOF)
                {
                    // End of notecard.
                    llOwnerSay("---EOF---");
                }
                else
                {
                    // do work here.
                    llOwnerSay(line);
                }
            }
        }
        // old system takes over if a NAK is encountered.
        if(request == noteCard_qry)
        {
            if(data == EOF)
            {
                // End of notecard encountered.
                llOwnerSay("EOF encountered");
            }
            else
            {
                // process normal notecard line, then read the next line
                // of the notecard.
                llOwnerSay(data);
                noteCard_qry = llGetNotecardLine(NOTECARD_NAME, ++noteCard_line);
             }
             }
         }
         }

Latest revision as of 11:49, 21 April 2024

Summary

Function: string llGetNotecardLineSync( string name, integer line );

Gets the line of the notecard name from the region's notecard cache immediately without raising a dataserver event.
Returns the string containing the text of the requested line from the notecard.

• string name a notecard in the inventory of the prim this script is in or a UUID of a notecard
• integer line Line number in a notecard (the index starts at zero).

line does not support negative indexes. Returns EOF if line is past the end of the notecard.

Specification

This function returns a string containing the requested line from a notecard in prim inventory, without the need for an asynchronous dataserver event, if the notecard is cached/known in its entirety by the simulator. This speeds up acessing notecard lines tremendously, and allows for near instantaneous random access.

If the notecard does not exist it returns the constant NAK and will shout a message to the debug channel. If the notecard has not been previously cached on the simulator it will return the NAK constant.

Notecards are cached into a fixed-size buffer, with the oldest (least-recently read) notecard getting removed first. It is not safe to assume a notecard has been previously cached. Data for a previously cached notecard may be dropped from the cache at any time, especially on a busy server.

Caveats

  • If line is out of bounds the script continues to execute without an error message.
  • 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 name is a new empty notecard (never saved) then an error "Couldn't find notecard ~NAME~" (~NAME~ being the value of name) will be shouted on the DEBUG_CHANNEL. This is because until a notecard is saved for the first time, it does not exist as an asset only as an inventory placeholder.
  • 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 than 1024 bytes the returned string will be truncated to the first 1024 bytes of the line.
  • A dataserver event does not get raised. Therefore, other scripts in the linkset are unaware of the processed notecard lines.
All Issues ~ Search JIRA for related Bugs

Examples

string NOTECARD_NAME = "notecard";
key READ_KEY = NULL_KEY;

default
{

    touch_start(integer total_number)
    {
        READ_KEY = llGetNumberOfNotecardLines(NOTECARD_NAME);
    }
    
    dataserver(key request, string data)
    {
        if (request == READ_KEY)
        {
            integer count = (integer)data;
            integer index;
            
            for (index = 0; index < (count+1); ++index)
            {
                string line = llGetNotecardLineSync(NOTECARD_NAME, index);
                if (line == NAK)
                {
                    llOwnerSay("---NAK---");
                }
                else if (line == EOF)
                {
                    llOwnerSay("---EOF---");
                }
                else
                {
                    llOwnerSay(line);
                }
            }
        }
    }
}

Following example to call a normal dataserver notecard read using llGetNotecardLine if llGetNotecardlineSync fails with a NAK. Keep in mind to clear any lists you are reading data into when using the following example to keep from corrupting the integrity of the list data.

// llGetNotecardLineSync example with fall back to the old dataserver read
// if llGetNotecardLineSync fails with a NAK.

string  NOTECARD_NAME = "notecard";
key     READ_KEY = NULL_KEY;

key     noteCard_qry;
integer noteCard_line;

default
{

    state_entry()
    {
        // read the notecards number of lines to the
        // simulators cache memory
        READ_KEY = llGetNumberOfNotecardLines(NOTECARD_NAME);
    }
    
    dataserver(key request, string data)
    {
        // read notecards using the new llGetNotecardLineSync function
        // from simulator cache.
        if (request == READ_KEY)
        {
            integer count = (integer)data;
            integer index;
            
            for (index = 0; index < (count+1); ++index)
            {
                string line = llGetNotecardLineSync(NOTECARD_NAME, index);
                if (line == NAK)
                {
                    // Got a notecard NAK meaning llGetNotecardLineSync had and error.
                    // falling back to the old dataserver event to read notecards.
                    llOwnerSay("---NAK---");
                    noteCard_qry = llGetNotecardLine(NOTECARD_NAME, noteCard_line);
                    return;  // return is needed to break the for/next loop once the NAK is encountered.
                }
                else if (line == EOF)
                {
                    // End of notecard.
                    llOwnerSay("---EOF---");
                }
                else
                {
                    // do work here.
                    llOwnerSay(line);
                }
            }
        }

        // old system takes over if a NAK is encountered.
        if(request == noteCard_qry)
        {
            if(data == EOF)
            {
                // End of notecard encountered.
                llOwnerSay("EOF encountered");
            }
            else 
            {
                // process normal notecard line, then read the next line
                // of the notecard.
                llOwnerSay(data);
                noteCard_qry = llGetNotecardLine(NOTECARD_NAME, ++noteCard_line);
            }
        }
    }
}

See Also

Deep Notes

Search JIRA for related Issues

Signature

function string llGetNotecardLineSync( string name, integer line );