Notecard Configuration Reader by Maddox Deluxe

From Second Life Wiki
Revision as of 20:05, 22 April 2014 by Maddox Deluxe (talk | contribs)
Jump to navigation Jump to search
First make a note card called (Category Theme).Fantasy and copy the data of this one into it. The 00000000-0000-0000-0000-000000000000 just means no floor drop.

Content here. More content.


// our test notecard
[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
Faster for 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
Our main script called (CODE).Notecard.Reader


<lsl> // Notecard Multi-line entries Configuration Reader v1.1 by Maddox Deluxe // This script is free; you can redistribute it and/or modify it // Just read the comments on the script

key NotecardQueryId; // key name of the notecard key LineRequestID; // notecard line count integer LineTotal; // The number of lines in the notecard integer LineIndex; // index for data read requests

string Author_Name = ""; // variable for setting author name string Menu_Button_Name = ""; // variable for setting menu button name to the themes list string Back_Drop_UUID = ""; // variable for setting backdrop uuid key to the themes list string Floor_Drop_UUID = ""; // variable for setting floor drop uuid key to the themes list

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.\nAuthor Name: "+(string)Author_Name+ "\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 str = llList2String(Found,0);   
           if (str == search) 
           return TRUE; // was found
       }
       return FALSE; // was not found
}

// Checks the uuid keys in the notecard, making sure they are real keys integer isKey(key check) {

   if (llStringLength(check) != 36)
       return FALSE;


   // Hyphenation test:
   if  (     (llGetSubString(check, 8, 8) != "-")
         ||  (llGetSubString(check, 13, 13) != "-")
         ||  (llGetSubString(check, 18, 18) != "-")
         ||  (llGetSubString(check, 23, 23) != "-"))
           return FALSE;

   // Remove dashes
   check = llDeleteSubString(llDeleteSubString(llDeleteSubString(llDeleteSubString((string)check, 8, 8), 12, 12), 16, 16), 20, 20);
   // Hex test
   integer i;
   for (i = 0; i < 32; i+=4) 
   {
       string char = llGetSubString(check, i, i+3 );
       if ((integer)("0x"+char) == 0 && char != "0000") 
           return FALSE;
   }
   return TRUE; // Passed all tests

} // notecard initialization NoteCardInit(string GrabNoteCardName, key id) // key id could be use for dialog message or llInstantMessage {

 if(llGetInventoryType(GrabNoteCardName) != INVENTORY_NOTECARD)
   {
 llInstantMessage(id,"Theme note card was not found "+(string)GrabNoteCardName+".");
  return;   
   }
   LineRequestID = llGetNumberOfNotecardLines(GetNoteName); // total number of lines in the notecard
   Themes = [];      // clear the themes list
   LineIndex = 0;    // start reading from line 0
   ThemesCount = 0;  // start adding from 0
   NotecardQueryId = llGetNotecardLine(GetNoteName, LineIndex);
   llInstantMessage(id,"Please stand by, reading themes configuration for " +GetNoteName);

}

ProcessThemes(string data, key id) // key id could be use for dialog message or llInstantMessage { list cmd; string cmd_grab; string value; ThemesCount;

// 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 notecard configuration
        if(IsElement(Themes,"Fantasy Car")==TRUE)
        {
         DumpListFind(Themes,"Fantasy Car");
         return;
        }
        else
        return;
        }
        if(data != "")
        {
            // lets move on and read the next line
            NotecardQueryId = llGetNotecardLine(GetNoteName, ++LineIndex);
           
           // cut off any leading blanks
           // ignore blank or comment lines
           if (llGetSubString(data, 0, 1) != "//" && llStringTrim(data, STRING_TRIM) != "" )
           {
           cmd = llParseString2List(data, ["="], []);
           cmd_grab = llStringTrim(llToLower(llList2String(cmd, 0)),STRING_TRIM);
           value = llStringTrim(llList2String(cmd, 1), STRING_TRIM);
   
            if(cmd_grab == "[author name]")
            {
            Author_Name = value;
           // error checking for Author Name
           if(value == "")
            {
           llInstantMessage(id,"Themes Configuration Error on line: " +(string)LineIndex+ ". 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)LineIndex+ ". Menu Button Name can not be empty.");
            return;
            }
           }
           else
           if(cmd_grab == "[backdrop texture uuid]")
           {
           Back_Drop_UUID = value;
           // error checking for BackDrop Texture UUID
           if(value == "" || (isKey(llToLower((string)value)) != TRUE))
           {
            llInstantMessage(id,"Themes Configuration Error on line: " +(string)LineIndex+ ". (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 = value;
           // error checking for FloorDrop Texture UUID
           if(value == "" || (isKey(llToLower((string)value)) != TRUE))
           {
            llInstantMessage(id,"Themes Configuration Error on line: " +(string)LineIndex+ ". (1) The Floor-drop Texture UUID is empty. (2) The Floor-drop UUID is not a key.");
           return;
           }
           ThemesCount = ThemesCount +1; // add +1 to our themes count
       }

// add to our test list database Themes += [Menu_Button_Name,Back_Drop_UUID,Floor_Drop_UUID];

          }
       }
   } 

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 notecard 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>

Test Run Output
---------------
Dump testing for list database search.
Author Name: Maddox Deluxe
Button Name: Fantasy Car
Backdrop Texture: 8f304cf2-7120-24e2-d1f1-db6b31bd6f6c
Floor drop Texture: 00000000-0000-0000-0000-000000000000

List Dump Found Test: Fantasy Car,8f304cf2-7120-24e2-d1f1-db6b31bd6f6c,00000000-0000-0000-0000-000000000000