Difference between revisions of "Notecard reading"
Jump to navigation
Jump to search
m (<lsl> tag to <source>) |
m (Replaced <source> with <syntaxhighlight> and minor formatting) |
||
Line 1: | Line 1: | ||
Here is a notecard reading template I use as a starting point. | Here is a notecard reading template [[User:Gigs Taggart|I]] use as a starting point. | ||
<syntaxhighlight lang="lsl2"> | |||
< | |||
//Notecard Reading template | //Notecard Reading template | ||
//Copyright 2007, Gigs Taggart | //Copyright 2007, Gigs Taggart | ||
//Released under BSD license | //Released under BSD license | ||
// | //https://opensource.org/license/BSD-2-Clause | ||
key gSetupQueryId; | key gSetupQueryId; | ||
Line 19: | Line 18: | ||
{ | { | ||
gSetupNotecardLine = 0; | gSetupNotecardLine = 0; | ||
gSetupQueryId = llGetNotecardLine(gSetupNotecardName,gSetupNotecardLine); | gSetupQueryId = llGetNotecardLine(gSetupNotecardName, gSetupNotecardLine); | ||
} | } | ||
Line 36: | Line 35: | ||
{ | { | ||
list tmp = llParseString2List(data, ["="], []); | list tmp = llParseString2List(data, ["="], []); | ||
string setting = llList2String(tmp,0); | string setting = llList2String(tmp, 0); | ||
if (setting == "password") | if (setting == "password") | ||
{ | { | ||
gPassword=llList2String(tmp,1); | gPassword=llList2String(tmp, 1); | ||
} | } | ||
//add more if statements here, for each config variable | //add more if statements here, for each config variable | ||
//you can also do stuff like variable=val1,val2,val3, simply | //you can also do stuff like variable=val1,val2,val3, simply | ||
//do llCSV2List(llList2String(tmp,1)); | //do llCSV2List(llList2String(tmp, 1)); | ||
gSetupQueryId = llGetNotecardLine(gSetupNotecardName,++gSetupNotecardLine); | gSetupQueryId = llGetNotecardLine(gSetupNotecardName, ++gSetupNotecardLine); | ||
} | } | ||
else | else | ||
Line 56: | Line 55: | ||
changed(integer change) | changed(integer change) | ||
{ | { | ||
if (change&CHANGED_INVENTORY) | if (change & CHANGED_INVENTORY) | ||
llResetScript(); | llResetScript(); | ||
} | } | ||
Line 66: | Line 65: | ||
changed(integer change) | changed(integer change) | ||
{ | { | ||
if (change&CHANGED_INVENTORY) | if (change & CHANGED_INVENTORY) | ||
llResetScript(); | llResetScript(); | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> | ||
[[Category: LSL Examples]] | [[Category: LSL Examples]] |
Latest revision as of 11:40, 29 April 2024
Here is a notecard reading template I use as a starting point.
//Notecard Reading template
//Copyright 2007, Gigs Taggart
//Released under BSD license
//https://opensource.org/license/BSD-2-Clause
key gSetupQueryId;
integer gSetupNotecardLine;
string gSetupNotecardName = "setup";
//define config variables here
string gPassword;
readSettingsNotecard()
{
gSetupNotecardLine = 0;
gSetupQueryId = llGetNotecardLine(gSetupNotecardName, gSetupNotecardLine);
}
default
{
state_entry()
{
readSettingsNotecard();
}
dataserver(key queryId, string data)
{
if(queryId == gSetupQueryId)
{
if(data != EOF)
{
list tmp = llParseString2List(data, ["="], []);
string setting = llList2String(tmp, 0);
if (setting == "password")
{
gPassword=llList2String(tmp, 1);
}
//add more if statements here, for each config variable
//you can also do stuff like variable=val1,val2,val3, simply
//do llCSV2List(llList2String(tmp, 1));
gSetupQueryId = llGetNotecardLine(gSetupNotecardName, ++gSetupNotecardLine);
}
else
{
state running;
}
}
}
changed(integer change)
{
if (change & CHANGED_INVENTORY)
llResetScript();
}
}
state running
{
changed(integer change)
{
if (change & CHANGED_INVENTORY)
llResetScript();
}
}