Who Is Online

2
Online

Wednesday, 15 August 2018 14:19

Example of a notecard Reader

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();
    }
}

 

Flash Scratch to SL - Your Scripting Tool

Script ImageNeed to write a LSL script and don't know how to script?  I know I hate trying to get my head around LSLS when I an in a time crunch. So why not give Flash Scratch a try! Its a great tool for learning and scoding your own scripts for Second Life without having to pay someone to do it and without a crash course in LSL

A Huge thanks to John Bennet of ATLAS Institute at University of Colorado and Eric Rosenbaum at MIT for writing Scratch for SL to begin with.

Read more: Flash Scratch to SL - Your Scripting Tool