Difference between revisions of "Basic Notecard Reader"
Jump to navigation
Jump to search
Omei Qunhua (talk | contribs) m (dupl. tag) |
|||
(4 intermediate revisions by 4 users not shown) | |||
Line 3: | Line 3: | ||
==Introduction== | ==Introduction== | ||
Quite often i read in configuration settings from a notecard. I thought i should stick up the core part of my notecard reading script. It's not exactly rocket science but hoepfully it's useful. | |||
==The Script== | ==The Script== | ||
< | <source lang="lsl2"> | ||
string NOTECARD = "notecard"; | |||
string | |||
integer intLine1; | integer intLine1; | ||
key keyConfigQueryhandle; | key keyConfigQueryhandle; | ||
key keyConfigUUID; | key keyConfigUUID; | ||
default | default | ||
{ | { | ||
state_entry() | state_entry() | ||
{ | { | ||
Line 47: | Line 23: | ||
state main; | state main; | ||
} | } | ||
keyConfigQueryhandle = llGetNotecardLine(NOTECARD, intLine1); | |||
keyConfigUUID = llGetInventoryKey(NOTECARD); | |||
} | } | ||
dataserver(key keyQueryId, string strData) | dataserver(key keyQueryId, string strData) | ||
{ | { | ||
if (keyQueryId == keyConfigQueryhandle) | if (keyQueryId == keyConfigQueryhandle) | ||
{ | { | ||
if (strData | if (strData == EOF) | ||
state main; | |||
keyConfigQueryhandle = llGetNotecardLine(NOTECARD, ++intLine1); | |||
strData = llStringTrim(strData, STRING_TRIM_HEAD); // Trim Whitespace; (not mandatory; if you use a space as marker you must erase this line | |||
if (llGetSubString (strData, 0, 0) != "#") // is it a comment? | |||
{ | { | ||
// | // OK .. now we do somthing in here with our notecard | ||
} | } | ||
} | } | ||
} | } | ||
} | } | ||
state main | state main | ||
Line 82: | Line 49: | ||
state_entry() | state_entry() | ||
{ | { | ||
// | // rest of script execution here | ||
} | } | ||
changed(integer intChange) | |||
changed(integer intChange) | |||
{ | { | ||
if (intChange & CHANGED_INVENTORY) | if (intChange & CHANGED_INVENTORY) | ||
{ // If the notecard has changed, then reload the notecard | { // If the notecard has changed, then reload the notecard | ||
if (keyConfigUUID != llGetInventoryKey(NOTECARD)) | if (keyConfigUUID != llGetInventoryKey(NOTECARD)) | ||
llResetScript(); | |||
} | } | ||
} | } | ||
} | } | ||
</ | </source> | ||
==See also== | ==See also== | ||
*[[ Script_Library | Script Library ]] | *[[ Script_Library | Script Library ]] |
Latest revision as of 12:24, 24 March 2016
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Basic Notecard Reader
Introduction
Quite often i read in configuration settings from a notecard. I thought i should stick up the core part of my notecard reading script. It's not exactly rocket science but hoepfully it's useful.
The Script
string NOTECARD = "notecard";
integer intLine1;
key keyConfigQueryhandle;
key keyConfigUUID;
default
{
state_entry()
{
if (llGetInventoryType(NOTECARD) == INVENTORY_NONE)
{
llSay(DEBUG_CHANNEL, "The notecard '"+NOTECARD+"' is missing!");
state main;
}
keyConfigQueryhandle = llGetNotecardLine(NOTECARD, intLine1);
keyConfigUUID = llGetInventoryKey(NOTECARD);
}
dataserver(key keyQueryId, string strData)
{
if (keyQueryId == keyConfigQueryhandle)
{
if (strData == EOF)
state main;
keyConfigQueryhandle = llGetNotecardLine(NOTECARD, ++intLine1);
strData = llStringTrim(strData, STRING_TRIM_HEAD); // Trim Whitespace; (not mandatory; if you use a space as marker you must erase this line
if (llGetSubString (strData, 0, 0) != "#") // is it a comment?
{
// OK .. now we do somthing in here with our notecard
}
}
}
}
state main
{
state_entry()
{
// rest of script execution here
}
changed(integer intChange)
{
if (intChange & CHANGED_INVENTORY)
{ // If the notecard has changed, then reload the notecard
if (keyConfigUUID != llGetInventoryKey(NOTECARD))
llResetScript();
}
}
}