Notecard Configuration Reader by Maddox Deluxe
Notecard Configuration Reader by Maddox Deluxe
// Our test note card Author Name=Maddox Deluxe // Theme [1] Menu Button Name=Fantasy Tiger BackDrop Texture UUID=8f304cf2-7120-24e2-d1f1-db6b31bd6f6c FloorDrop Texture UUID=00000000-0000-0000-0000-000000000000 // Theme [2] Menu Button Name=Fantasy Car BackDrop Texture UUID=517b2288-67ca-b14c-1de2-c5f5fdf5291f FloorDrop Texture UUID=00000000-0000-0000-0000-000000000000 // Theme [3] Menu Button Name=Fantasy Tree BackDrop Texture UUID=f6321118-cc24-6230-78a5-a257a3e33378 FloorDrop Texture UUID=00000000-0000-0000-0000-000000000000
// Optimized for faster loading Author Name=Maddox Deluxe Menu Button Name=Fantasy Tiger BackDrop Texture UUID=8f304cf2-7120-24e2-d1f1-db6b31bd6f6c FloorDrop Texture UUID=00000000-0000-0000-0000-000000000000 Menu Button Name=Fantasy Car BackDrop Texture UUID=517b2288-67ca-b14c-1de2-c5f5fdf5291f FloorDrop Texture UUID=00000000-0000-0000-0000-000000000000 Menu Button Name=Fantasy Tree BackDrop Texture UUID=f6321118-cc24-6230-78a5-a257a3e33378 FloorDrop Texture UUID=00000000-0000-0000-0000-000000000000
- very fast note card reader
<lsl> // Notecard Configuration Reader by Maddox Deluxe // This script is free; you can redistribute it and/or modify it // Just read the comments on the script
key notecardQueryId; //name key of the notecard integer line; // note card line tracker
// Variables string Author_Name = ""; string Menu_Button_Name = ""; string Back_Drop_UUID = ""; string Floor_Drop_UUID = ""; string data; // note card data string GetNoteName; // incoming note card name
list Themes; // our list database for testing
integer ThemesCount; // counts how many themes they are in the note card configuration
key User; // user tracker key
// Function by Maddox Deluxe // test to dump all 3 elements in the list that goes with each other. DumpListFind(list db, string name) {
integer index = llListFindList(db, [name]); if (~index) { list Found = llList2List(db, index, index + 2); string BN = llList2String(Found,0); string BD = llList2String(Found,1); string FD = llList2String(Found,2); llOwnerSay("Dump testing for list database search.\nButton Name: "+(string)BN+ "\nBackdrop Texture: "+(string)BD+ "\nFloor drop Texture: "+(string)FD); llOwnerSay("List Dump Found Test: "+llDumpList2String(Found, ",")); // llMessageLinked(LINK_SET, 0,"SET BACKDROP TEXTURE",(string)BD); if(FD != "00000000-0000-0000-0000-000000000000") { // llMessageLinked(LINK_SET, 0,"SET FLOOR DROP TEXTURE",(string)FD); } }
} // Function by Maddox Deluxe // looks for 3 elements and the search string is the first element of the set integer IsElement(list db, string search) {
integer index = llListFindList(db, [search]); if (~index) { list Found = llList2List(db, index, index + 2); string i = llList2String(Found,0); if (i == search) return TRUE; // was found } return FALSE; // was not found
} // just for testing on this demo script to check keys integer isKey(key test) {
if (llStringLength(test) != 36) return FALSE;
// Hyphenation test: if ( (llGetSubString(test, 8, 8) != "-") || (llGetSubString(test, 13, 13) != "-") || (llGetSubString(test, 18, 18) != "-") || (llGetSubString(test, 23, 23) != "-")) return FALSE; // Remove dashes test = llDeleteSubString(llDeleteSubString(llDeleteSubString(llDeleteSubString((string)test, 8, 8), 12, 12), 16, 16), 20, 20); // Hex test integer i; for (i = 0; i < 32; i+=4) { string char = llGetSubString(test, i, i+3 ); if ((integer)("0x"+char) == 0 && char != "0000") return FALSE; } return TRUE; // Passed all tests
} // note card loader NoteCardInit(string GrabNoteCardName, key id) // key id could be use for dialog messages or llInstantMessages {
if(llGetInventoryType(GrabNoteCardName) != INVENTORY_NOTECARD) { llInstantMessage(id,"Theme note card was not found "+(string)GrabNoteCardName+"."); return; } Themes = [];// clear the themes list line = 0; //start reading from first line 0 ThemesCount = 0; // counts how many themes they are notecardQueryId = llGetNumberOfNotecardLines(GetNoteName); llInstantMessage(id,"Please stand by, reading themes configuration for " +GetNoteName);
}
ProcessThemes(string data, key id) // key id could be use for dialog messages or llInstantMessages { list cmd; string cmd_grab; string value;
// if we are at the end of the file
if(data == EOF) { llInstantMessage(id,"Done reading themes configuration for "+GetNoteName+ "\n\nTotal Themes: "+(string)ThemesCount); // lets use the 2nd search string for this test. The search strings are the button names in the note card configuration. string search_test = "Fantasy Car"; if(IsElement(Themes,search_test)==TRUE) { DumpListFind(Themes,search_test); return; } else return; } if(data != "") { // speed is the key when scripting, I always write fast codes
if ( llGetSubString(data, 0, 0) != "//" && llStringTrim(data, STRING_TRIM) != "" ) { integer index = llSubStringIndex(data, " "); if(~index) { cmd = llParseString2List(data, ["="], []);
cmd_grab = llStringTrim(llToLower(llList2String(cmd, 0)),STRING_TRIM); value = llStringTrim(llList2String(cmd, 1), STRING_TRIM);
// should always add block if statements for error checking
if(cmd_grab == "author name") { Author_Name = value; // error checking for Author Name if(value == "") { llInstantMessage(id,"Themes Configuration Error on line: " +(string)line+ ". Author Name can not be empty"); return; } } else if(cmd_grab == "menu button name") { Menu_Button_Name = value; // error checking for Menu Button Name if(value == "") { llInstantMessage(id,"Themes Configuration Error on line: " +(string)line+ ". Menu Button Name can not be empty"); return; } } else if(cmd_grab == "backdrop texture uuid") { Back_Drop_UUID = llToLower(value); // error checking for BackDrop Texture UUID if(value == "" || (isKey((string)value) != TRUE)) { llInstantMessage(id,"Themes Configuration Error on line: " +(string)line+ ". (1) The Backdrop Texture UUID is empty. (2) The Backdrop UUID is not a key."); return; } } else if(cmd_grab == "floordrop texture uuid") { Floor_Drop_UUID = llToLower(value); // error checking for FloorDrop Texture UUID if(value == "" || (isKey((string)value) != TRUE)) { llInstantMessage(id,"Themes Configuration Error on line: " +(string)line+ ". (1) The Floor-drop Texture UUID is empty. (2) The Floor-drop UUID is not a key."); return; }
// add to our test list database Themes += [Menu_Button_Name,Back_Drop_UUID,Floor_Drop_UUID];
ThemesCount = ThemesCount + 1; // we don't count the note lines } } } } // lets move on to the next lines in our note card configuration ++line; notecardQueryId = llGetNotecardLine(GetNoteName, line); } // we don't need a state entry to run this script, best thing is you don't even have to reset the script at all.
default {
link_message(integer sender_num, integer num, string str, key id) { if(str == "SetUserKey") { // sets up the user key that click the object User = (key)id; } if(str == "LoadThemes") { // loads up our test note card GetNoteName = id; NoteCardInit((string)GetNoteName, User);
} }
// Triggered when task receives asynchronous data
dataserver(key request_id, string data) { if(request_id == notecardQueryId) { ProcessThemes(data, User); }
}
} </lsl>
<lsl> // Our test script for loading the notecard // place this script with the main note card one and then just click the object
// our test notecard name for reading string NotecardName = "(Category Theme).Fantasy";
default {
state_entry() { }
touch_start(integer total_number) { key User = llDetectedKey(0); // sets the user key // sending user key to the note card reader script llMessageLinked(LINK_SET,0,"SetUserKey",User);
// sending the note card name to the note card reader script llMessageLinked(LINK_SET,0,"LoadThemes",(string)NotecardName); }
} </lsl>
Test Run Output --------------- Dump testing for list database search. Button Name: Fantasy Car Backdrop Texture: 517b2288-67ca-b14c-1de2-c5f5fdf5291f Floor drop Texture: 00000000-0000-0000-0000-000000000000 List Dump Found Test: Fantasy Car,517b2288-67ca-b14c-1de2-c5f5fdf5291f,00000000-0000-0000-0000-000000000000