Dataserver API
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Dataserver Framework
Introduction: the most common problem i find is people asking about dataservers, reading from notecards to bypass variables within a notecard so you can release your script as nomod. so i setup a simple system that i use time and time again that can be reused in any project. the class itself is state based meaning the default state reads the notecard and then starts another state when the notecard is read and ready to use i explain this further below.
Main Script:
string notecard_name = "configuration"; // name of notecard goes here key queryhandle; // to seperate Dataserver requests // UPDATES integer line ; // Config data loaded from notecard, with some sane defaults integer channel = 1000; string email_address = "revolution.perenti@skidzpartz.com"; default { changed(integer change) { // We want to reload channel notecard if it changed if (change & CHANGED_INVENTORY) { llResetScript(); } } state_entry() { queryhandle = llGetNotecardLine(notecard_name, line);// request line line++ ; } dataserver(key query_id, string data) { if (query_id == queryhandle) { // I've written this token parser so many times in so many languages... if (data != EOF) { // not at the end of the notecard // yay! Parsing time // first, is it a comment? or an empty line? if (llGetSubString (data, 0, 0) != "#" && llStringLength (data) > 0) { list parsed = llParseString2List (data, ["="], [""]) ; string token = llToLower (llStringTrim (llList2String (parsed, 0), STRING_TRIM)) ; if (token == "email_address") email_address = llStringTrim (llList2String (parsed, 1), STRING_TRIM) ; if (token == "channel") channel = (integer)llStringTrim (llList2String (parsed, 1), STRING_TRIM) ; } queryhandle = llGetNotecardLine(notecard_name, line); line++; } else { if (email_address == "") llOwnerSay ("NOTICE! No email_address specified. You will NOT receive purchase emails or status updates!") ; state configuration ; } } } } state configuration { state_entry() { llListen(channel, "", "", ""); llShout(0, "Channel set to " + (string)channel); llShout(0, "Email set to " + (string)email_address); } }
NOECARD:
# This is the configuration file channel = 1000 email_address = phoenixcms@hotmail.co.uk # end
USAGE: Ok lets explain how this works well the default state basailly reads all the lines for the notecard parces the lines into the notecard and we setup varables in the dataserver so we know if we want to overide a default value.
the dataserver consists over tokens for example
if (token == "email_address")
this means in the noecard there will be a value called email_address like our notecard above then followed by the read like
email_address = llStringTrim (llList2String (parsed, 1), STRING_TRIM) ;
as the notecard is string based there are ways to get this back into other values also very common usage within secondlife. being a string inside a notecard and you want the value as a float, vector, integer etc all you need todo is add (integer) after the command = for example
menu_timer = (integer)llStringTrim (llList2String (parsed, 1), STRING_TRIM) ;
this will convert the string into an integer.
For technical support, requests, etc., use the Search under the Groups Tab and search for .::Prototype::.
if you have any problems getting this script to work either contect me inworld Revolution Perenti or visit out Open Source Section at skidz partz we have many different versions of this system. Snow Crash