Example of a notecard Reader

Written by Kitsune

Example of how a notecard is read from a script (the notecard needs to be named 'config'):

//Remove this line for this script to work.

//This script is an example of how to read a notecard. It will allow you to set the configurations of Hovertext using a Notecard.


//PLEASE NOTE: THE NOTECARD WE WANT TO READ MUST BE IN THE SAME OBJECTS CONTENTS FOLDER AS THIS SCRIPT.


//Notecards are read form the first line BUT the first line is given the value of 0 so a 5 line notecard would be read like this:

// Line 0: This is the first line.
// Line 1: This is the second line.
// Line 2: This is the third line.
// Line 3: This is the forth line.
// Line 4: This is the fifth line.


string gName = "config";    //Name of notecard we wish to read

key HTextKey; //This is the key we will use to call for hovertext
key ColorKey; //This is the key we will use to call the color
key AlphaKey; //This is the key we will use to call the transparancy of teh text.


//Declaring variables to be used later.
string Htext;
vector Color;
float Alpha;
list temp;
default 
{
    state_entry() 
    {
        //Using the key below we can ask the script to read the notecard on certain lines..
        HTextKey = llGetNotecardLine(gName, 0);
        ColorKey = llGetNotecardLine(gName, 1);
        AlphaKey = llGetNotecardLine(gName, 2);
    }

    dataserver(key query_id, string data) 
    {
        temp = [];
        if(query_id == HTextKey)//Filtering the call
        {
            
            if (data != EOF) // not at the end of the notecard
            {
                temp = llParseString2List(data,[" = "],[]);
                Htext = (string)llList2String(temp,1); //Give Htext the same value as data.
                              //Data being what is read on the notecard.
            }
        }
        if(query_id == ColorKey)//Filtering the call
        {
            if (data != EOF) // not at the end of the notecard
            {
                temp = llParseString2List(data,[" = "],[]);
                Color = (vector)llList2String(temp,1); //Give Color the same value as data.
                                       //Data being what is read from the notecard
                                       //Also note that data is being casted as a vector as that is what we will need to set the color.
            }
        }
        if(query_id == AlphaKey)//Filtering the call
        {
            if (data != EOF) // not at the end of the notecard
            {
                temp = llParseString2List(data,[" = "],[]);
                Alpha = (float)llList2String(temp,1);//Give Alpha the same value as data.
                                     //data being what is read from the notecard.
                                     //Also note that data is being casted as a float as that is what is needed for the alpha.
 
 
                //Using the infomation retrieved we can now set up the hovertext.
                llSetText(Htext, Color, Alpha);
            }
        }
        llOwnerSay(Htext + "  " + (string)Color + "  " + (string)Alpha);
    }
    
    on_rez(integer start_param)
    {
        llResetScript();
    }
}