Category:LSL Notecard

From Second Life Wiki
Revision as of 12:28, 2 April 2010 by Erik Leominster (talk | contribs) (→‎Notecard Immutability: Added a new script to the section which was just now created for this purpose.)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Notecards & Parameters

In public domain scripts released with modify privileges, operational parameters (e.g. opening sounds for drawers, etc.) are usually set and changed right in the script by editing the script.

Scripted products that are sold, however, often use instead a notecard as the place where customers can change parameters to meet their individual needs. Doing this negates both the need to distribute proprietary scripts with modify privileges, and the need for customers to edit scripts (which most find frightening.)

To pull information from a notecard, you use the llGetNotecardLine function. As it comes into the script, it is captured in the dataserver event, during which event you parse the information and assign it to variables. There is an illustration of the procedure here: Notecard_reading.

Limits

Notecards are limited in several ways:

  • 64KiB
  • When read by script:
    • Only the first 255 bytes of each line are returned.
    • Cannot contain embedded assets.
  • Immutability. (They don't appear to be immutable, but they really are.)

Notecard Immutability

If you create a notecard, then you can easily edit the notecard and save changes. However internally within the Second Life asset server, notecard objects are immutable. This means that when you are editing the notecard, you are actually creating a new notecard with an entirely different key than the original notecard. (The avatar's or object's inventory will not contain a reference to the old notecard any more -- it is updated to reference the key of the new notecard.) The user probably thinks it is the same notecard object, but it is really an entirely new object.

This can be exploited in a script, to detect changes to a notecard and ignore other changes in an object's inventory. The following script illustrates this technique. The configuration notecard is read when the script is started, or when the configuration notecard itself changes. (It will have a new key, and this will trigger reading it to get the changes.) If something else changes in the object's inventory, then the change is ignored and the configuration notecard is not re-read. This can save a lot of overhead.

This script assumes that there is a notecard named "Configuration" in the object's inventory, and that one or more lines of text are stored in the notecard. <lsl>key kQuery; integer iLine = 0; string notecard_name = "Configuration"; key notecard_key = NULL_KEY;

config_init() {

   key nc_key = llGetInventoryKey(notecard_name);
   if (nc_key == notecard_key)
   {
       // Some other inventory item changed, not the configuration notecard.
       return; // Skip reading the notecard in this case.
   }
   // Remember the new notecard key from now on.
   notecard_key = nc_key;
   kQuery = llGetNotecardLine(notecard_name, iLine);

}

default {

   state_entry()
   {
       // Read the notecard once at startup.
       config_init();
   }
   changed(integer change)
   {
       if (change & CHANGED_INVENTORY)         
       {
           // Read the notecard when the inventory has changed.
           config_init();
       }
   }
   
   dataserver(key query_id, string data) 
   {
       if (query_id == kQuery) 
       {
           // this is a line of our notecard
           if (data == EOF) 
           {
               llOwnerSay("Finished reading configuration.");
           } 
           else 
           {
               // TODO: handle notecard line here.  For not just inform the owner.
               llOwnerSay("Read notecard line: " + data);
               // increment line count
               ++iLine;
               //request next line of notecard.
               kQuery = llGetNotecardLine(notecard_name, iLine);
           }
       }
   }

} </lsl>

Sharing Notecard Access

In the course of shared projects, you may often need to let team members access notecards in objects owned by you, or need yourself to access notecards in objects owned by them.

To enable this, see: Editing someone else's scripts and notecards.


Embedded Assets in Notecards

Notecards can contain embedded assets, such as textures, landmarks, etc.

These cannot be accessed via script.

Tip! While it appears that the contents of one notecard, text and embedded objects, can manually be copied from one notecard to a second notecard, in fact you won't be able to save that second notecard. What you must do is drag the embedded objects to your inventory, and then from there drag into the second notecard.

Pages in category "LSL Notecard"

The following 5 pages are in this category, out of 5 total.