Difference between revisions of "Basic Notecard Reader"
(Created page with '{{LSL Header}} =Basic Notecard Reader= ==Introduction== ==The Script== ==See also== * Script Library ') |
|||
Line 5: | Line 5: | ||
==The Script== | ==The Script== | ||
<lsl> | |||
// ******************************************************************** | |||
// | |||
// Base Notecard reader | |||
// | |||
// by SimonT Quinnell | |||
// | |||
// NOTE. This treats lines starting with '#' in the notecard as a comment | |||
// | |||
// ******************************************************************** | |||
// ******************************************************************** | |||
// CONSTANTS | |||
// ******************************************************************** | |||
string NOTECARD = "notecard"; | |||
// ******************************************************************** | |||
// Variables | |||
// ******************************************************************** | |||
// internals for reading notecards | |||
string strNotecard; | |||
integer intLine1; | |||
key keyConfigQueryhandle; | |||
key keyConfigUUID; | |||
default | |||
{ | |||
state_entry() | |||
{ | |||
if (llGetInventoryType(NOTECARD) == INVENTORY_NONE) | |||
{ | |||
llSay(DEBUG_CHANNEL, "The notecard '"+NOTECARD+"' is missing!"); | |||
state main; | |||
} | |||
else | |||
{ | |||
keyConfigQueryhandle = llGetNotecardLine(NOTECARD, intLine1 = 0); | |||
keyConfigUUID = llGetInventoryKey(NOTECARD); | |||
} | |||
} | |||
dataserver(key keyQueryId, string strData) | |||
{ | |||
if (keyQueryId == keyConfigQueryhandle) | |||
{ | |||
if (strData != EOF) | |||
{ | |||
string strToken; | |||
strData = llStringTrim(strData, STRING_TRIM_HEAD); // Trim Whitespace | |||
if (llGetSubString (strData, 0, 0) != "#") // is it a comment? | |||
{ | |||
// OK .. now we do somthing in here with our notecard | |||
} | |||
keyConfigQueryhandle = llGetNotecardLine(strNotecard, ++intLine1); | |||
} | |||
else | |||
{ | |||
// Finished reasding the notecard | |||
state main; | |||
} | |||
} | |||
} | |||
} | |||
state main | |||
{ | |||
state_entry() | |||
{ | |||
// | |||
} | |||
changed(integer intChange) | |||
{ | |||
if (intChange & CHANGED_INVENTORY) | |||
{ // If the notecard has changed, then reload the notecard | |||
if (keyConfigUUID != llGetInventoryKey(NOTECARD)) | |||
{ | |||
state default; | |||
} | |||
} | |||
} | |||
} | |||
</lsl> | |||
==See also== | ==See also== | ||
*[[ Script_Library | Script Library ]] | *[[ Script_Library | Script Library ]] |
Revision as of 20:41, 13 October 2010
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Basic Notecard Reader
Introduction
The Script
<lsl> // ******************************************************************** // // Base Notecard reader // // by SimonT Quinnell // // NOTE. This treats lines starting with '#' in the notecard as a comment // // ********************************************************************
// ******************************************************************** // CONSTANTS // ********************************************************************
string NOTECARD = "notecard";
// ********************************************************************
// Variables
// ********************************************************************
// internals for reading notecards
string strNotecard;
integer intLine1;
key keyConfigQueryhandle;
key keyConfigUUID;
default
{
state_entry() { if (llGetInventoryType(NOTECARD) == INVENTORY_NONE) { llSay(DEBUG_CHANNEL, "The notecard '"+NOTECARD+"' is missing!"); state main; } else { keyConfigQueryhandle = llGetNotecardLine(NOTECARD, intLine1 = 0); keyConfigUUID = llGetInventoryKey(NOTECARD); } } dataserver(key keyQueryId, string strData) { if (keyQueryId == keyConfigQueryhandle) { if (strData != EOF) { string strToken; strData = llStringTrim(strData, STRING_TRIM_HEAD); // Trim Whitespace if (llGetSubString (strData, 0, 0) != "#") // is it a comment? { // OK .. now we do somthing in here with our notecard } keyConfigQueryhandle = llGetNotecardLine(strNotecard, ++intLine1); } else { // Finished reasding the notecard state main; } } }
}
state main
{
state_entry() { // } changed(integer intChange) { if (intChange & CHANGED_INVENTORY) { // If the notecard has changed, then reload the notecard if (keyConfigUUID != llGetInventoryKey(NOTECARD)) { state default; } }
}
} </lsl>