Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: 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
Original Thread
10-17-2006 16:06
/15/2e/142972/1.html
_____________________
i've got nothing. ;)
Zeera Xi
Real Join Date: Mid '05
Join date: 21 Sep 2006
Posts: 54
10-17-2006 16:17
Wow, cool idea and thanks a lot!

And this doesn't count only for notecard names, hell, you could even set the scripts own name for permament information storage. Just shame that LSL isn't capable of changing the object and item names in an inventory, it would add alot of possiblities together with all the other alternative information storaging ( example is the object name or description ).

Btw, as per Wiki notes and I quote: "Note: item names may be up to 63 characters long.", But that is quite a lot of information if you use it wisely. Example is to use HEX or Bitfields to help store even more information cleverly!
Vares Solvang
It's all Relative
Join date: 26 Jan 2005
Posts: 2,235
10-28-2006 12:03
Very clever! Thanks for posting this.
_____________________
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
12-11-2006 11:57
Be careful with this kind of thing because the first word of any notecard in the inventory might match even if it's not a config. I'd recommend using a keyword as the first word for every notecard, to avoid confusion. For example:

MyScript SpeedupTimer True
MyScript Sound False
MyScript Mode Continuous

Otherwise, if this method becomes popular, think of what a mess your customers will end up with! Configuring one object affects another, simply because they both have a "mode" config.

Also, a word of caution. My understanding is that data server has a time penalty to limit scripters from flooding the sim with information requests. It happens on purpose, not because LL can't implement it more efficiently. Therefore, use this kind of config with restraint. If LL finds we're using it willy-nilly and it's slowing down the sims, they'll add a penalty and we lose the benefit.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-11-2006 15:34
From: Learjeff Innis
Be careful with this kind of thing because the first word of any notecard in the inventory might match even if it's not a config. I'd recommend using a keyword as the first word for every notecard, to avoid confusion. For example:

MyScript SpeedupTimer True
MyScript Sound False
MyScript Mode Continuous

Otherwise, if this method becomes popular, think of what a mess your customers will end up with! Configuring one object affects another, simply because they both have a "mode" config.


Since the notecards are explicitly in the objects inventory this is a relatively small risk, unless of course your customer dragged it out of one object, into inventory and then back into a second object?

Personally I use keyword=value pairing as its not subject to accidents of the misinterpretted form, If I dont see a = seperator I dont process anything.
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
12-11-2006 18:02
Right, good point.