Difference between revisions of "Basic Notecard Reader"

From Second Life Wiki
Jump to navigation Jump to search
m (You guys need to fix your LSL source tags :/)
(Script diddn't compile ... etc. etc.)
Line 9: Line 9:


<source lang="lsl2">
<source lang="lsl2">
// ********************************************************************
<source lang="lsl2">
//
string     NOTECARD = "notecard";
// Base Notecard reader
//
// by SimonT Quinnell
//
//  NOTE.  This treats lines starting with '#' in the notecard as a comment
//
// ********************************************************************
 
// ********************************************************************
// CONSTANTS
// ********************************************************************
 
string NOTECARD = "notecard";
 
 
// ********************************************************************
// Variables
// ********************************************************************
 
 
// internals for reading notecards
string      strNotecard;
integer    intLine1;
integer    intLine1;
key        keyConfigQueryhandle;                  
key        keyConfigQueryhandle;
key        keyConfigUUID;
key        keyConfigUUID;


default
default
{          
{
     state_entry()
     state_entry()
     {
     {
Line 49: Line 24:
             state main;
             state main;
         }
         }
         else
         keyConfigQueryhandle = llGetNotecardLine(NOTECARD, intLine1);
        {
        keyConfigUUID = llGetInventoryKey(NOTECARD);
            keyConfigQueryhandle = llGetNotecardLine(NOTECARD, intLine1 = 0);
            keyConfigUUID = llGetInventoryKey(NOTECARD);
        }
     }
     }
   
 
     dataserver(key keyQueryId, string strData)
     dataserver(key keyQueryId, string strData)
     {
     {
         if (keyQueryId == keyConfigQueryhandle)
         if (keyQueryId == keyConfigQueryhandle)
         {
         {
             if (strData != EOF)
             if (strData == EOF)
            {             
                string strToken;
                strData = llStringTrim(strData, STRING_TRIM_HEAD);      // Trim Whitespace
                if (llGetSubString (strData, 0, 0) != "#")              // is it a comment?
                {
                    // OK .. now we do somthing in here with our notecard
                }
                keyConfigQueryhandle = llGetNotecardLine(strNotecard, ++intLine1);
            }
            else
            {
                // Finished reasding the notecard
                 state main;
                 state main;
            }
        }         
    }
}


            keyConfigQueryhandle = llGetNotecardLine(NOTECARD, ++intLine1);


state main
            strData = llStringTrim(strData, STRING_TRIM_HEAD);      // Trim Whitespace; (not mandatory; if you use a space as marker you must erase this line
{
             if (llGetSubString (strData, 0, 0) != "#")             // is it a comment?
    state_entry()
    {
        //
    }
   
    changed(integer intChange)       
    {
        if (intChange & CHANGED_INVENTORY)
        {  // If the notecard has changed, then reload the notecard
             if (keyConfigUUID != llGetInventoryKey(NOTECARD))
             {
             {
                 state default;
                 // OK .. now we do somthing in here with our notecard
             }
             }
         }
         }
     }
     }
}
}


//*********************************************
//THIS IS THE SCRIPT CORRECTED BY BLADE GAELYTH
//The original one doesn't run
//*********************************************
string      NOTECARD = "notecard" // internals for reading notecards
//string    strNotecard; (useless)
integer    intLine1;
key        keyConfigQueryhandle;                 
key        keyConfigUUID;
default
{           
    state_entry()
    {
        if (llGetInventoryType(NOTECARD) == INVENTORY_NONE)
        {
            llSay(DEBUG_CHANNEL, "The notecard '"+NOTECARD+"'  is missing!");
            state main;
        }
        else
        {
            keyConfigQueryhandle = llGetNotecardLine(NOTECARD, intLine1 = 0);
            keyConfigUUID = llGetInventoryKey(NOTECARD);
        }
    }
    dataserver(key keyQueryId, string strData)
    {
        if (keyQueryId == keyConfigQueryhandle)
        {
            if (strData != EOF)
            {             
                //string strToken; (useless)
                strData = llStringTrim(strData, STRING_TRIM_HEAD);      // Trim Whitespace; (not mandatory; if you use a space as marker you must erase this line
                if (llGetSubString (strData, 0, 0) != "#")              // is it a comment?
                {
                    // OK .. now we do somthing in here with our notecard
                }
                //keyConfigQueryhandle = llGetNotecardLine(strNotecard, ++intLine1); (wrong line)
                keyConfigQueryhandle = llGetNotecardLine(NOTECARD, ++intLine1);
            }
            else
            {
                // Finished reasding the notecard
                state main;
            }
        }         
    }
}
state main
state main
{
{
     state_entry()
     state_entry()
     {
     {
         //
         // rest of script execution here
     }
     }
     changed(integer intChange)
     changed(integer intChange)        
     {
     {
         if (intChange & CHANGED_INVENTORY)
         if (intChange & CHANGED_INVENTORY)
         {  // If the notecard has changed, then reload the notecard
         {  // If the notecard has changed, then reload the notecard
             if (keyConfigUUID != llGetInventoryKey(NOTECARD))
             if (keyConfigUUID != llGetInventoryKey(NOTECARD))
            {
                 llResetScript();
                 state default;
            }
         }
         }
     }
     }
}
}

Revision as of 13:22, 24 March 2016

Basic Notecard Reader

Introduction

Quite often i read in configuration settings from a notecard. I thought i should stick up the core part of my notecard reading script. It's not exactly rocket science but hoepfully it's useful.

The Script

<source lang="lsl2">
string      NOTECARD = "notecard";
integer     intLine1;
key         keyConfigQueryhandle;
key         keyConfigUUID;

default
{
    state_entry()
    {
        if (llGetInventoryType(NOTECARD) == INVENTORY_NONE)
        {
            llSay(DEBUG_CHANNEL, "The notecard '"+NOTECARD+"'  is missing!");
            state main;
        }
        keyConfigQueryhandle = llGetNotecardLine(NOTECARD, intLine1);
        keyConfigUUID = llGetInventoryKey(NOTECARD);
    }

    dataserver(key keyQueryId, string strData)
    {
        if (keyQueryId == keyConfigQueryhandle)
        {
            if (strData == EOF)
                state main;

            keyConfigQueryhandle = llGetNotecardLine(NOTECARD, ++intLine1);

            strData = llStringTrim(strData, STRING_TRIM_HEAD);      // Trim Whitespace; (not mandatory; if you use a space as marker you must erase this line
            if (llGetSubString (strData, 0, 0) != "#")              // is it a comment?
            {
                // OK .. now we do somthing in here with our notecard
            }
        }
    }
}

state main
{
    state_entry()
    {
        // rest of script execution here
    }
    changed(integer intChange)
    {
        if (intChange & CHANGED_INVENTORY)
        {   // If the notecard has changed, then reload the notecard
            if (keyConfigUUID != llGetInventoryKey(NOTECARD))
                llResetScript();
        }
    }
}

See also