Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

High Speed Config Loading

Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
10-12-2006 15:51
I thought I'd share the code I use to load configuration data in a script. Compared to reading notecards, this method is lightning fast.
There is NO DataServer event calls required.

The script snippet below will look at any notecards that are in the objects inventory and parse the name of each notecard for commands and parameters.

All notecards in this case follow the <name> <value> naming scheme. This means, to store a setting you'd add a notecard and rename it to contain the proper name / value pair. Values are separated by SPACEs in this case.

Ex:
CODE
SpeedupTimer True

CODE
Sound False

CODE
Mode Continuous


The code below will retrieve the notecard names, convert them to lower case, then split them up into a list and finally examine the first list element and compare it to a set of known commands or variables.

Depending on the value of the set, you'll have to add in the proper evaluation method. You know how to use if /else (if), do you?

If you require the proper case for some parameters, simply extract them from the notecard name. llSubString() is your friend :)

Note:
Do NEVER store passwords of any kind using this method. People can look at an objects inventory contents. You have been warned!

CODE

// Setting default values. (Just add the config notecards that differ..)
integer Mode;
integer SpeedupTimer;
integer Sound;
string Title = "Blah";
integer DEBUG = 0;

default {
state_entry() {
// Required so the script will actually compile...
}
}

state ReadConfig
{
on_rez(integer Param) {llResetScript();}

state_entry()
{
integer Cnt = llGetInventoryNumber(INVENTORY_NOTECARD);
integer X;
float Y;
list Cfg = [];
string Dots = "";
string Cmd = "";
string Dummy = "";
if (Cnt > 0) {
if (DEBUG) {llOwnerSay("Reading Configuration");}
for (X=0;X<Cnt;X++) {
Dots = (Dots = "") + Dots + ".";
llSetText(Title + "\n \nReading Configuration" + Dots,<1,0,0>,1);
// Parse the name to a list...
Cfg = llParseString2List(llToLower(llGetInventoryName(INVENTORY_NOTECARD,X)), [" "], []);
// Get the first list element
Cmd = llList2String(Cfg,0);
// Get the first parameter.
Dummy = llList2String(Cfg,1);
// Do the comparisons. Add yours here.
if (Cmd == "mode") {
if (Dummy == "single") {
Mode = 1;
} else if (Dummy == "continuous") {
Mode = 2;
} else {
Mode = 1;
if (DEBUG) {llOwnerSay("Unknown Game Mode '" + Dummy + "' !");}
}
}
if (Cmd == "speeduptimer") {
if (Dummy == "true") {
SpeedupTimer = TRUE;
} else if (Dummy=="false") {
SpeedupTimer = FALSE;
} else {
SpeedupTimer = TRUE;
if (DEBUG) {llOwnerSay("SpeedupTimer must be either TRUE or FALSE!");}
}
}
if (Cmd == "sound") {
if (Dummy == "true") {
Sound = TRUE;
} else if (Dummy=="false") {
Sound = FALSE;
} else {
Sound = TRUE;
if (DEBUG) {llOwnerSay("Sound must be either TRUE or FALSE!");}
}
}
}
}
if (DEBUG) {llOwnerSay("Done.");}
// state Offline;
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
10-17-2006 16:06
/54/49/144016/1.html
_____________________
i've got nothing. ;)