Difference between revisions of "Touch A Quote"

From Second Life Wiki
Jump to navigation Jump to search
m (added {{LSL Header}} {{LSLC|Examples}} {{LSLC|Library}})
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:
In the same object you drop this script, create a notecard called "_quotes" and simply put your quotes in it, max. 255 characters per line or they will be truncated. Watch out not to bust the script memory stack by adding too much, but you can use Mono to compile it and create a very long notecard.
In the same object you drop this script, create a notecard called "_quotes" and simply put your quotes in it, max. 255 characters per line or they will be truncated. Watch out not to bust the script memory stack by adding too much, but you can use Mono to compile it and create a very long notecard.


<lsl>
<source lang="lsl2">


// Touch a quote script  
// Touch a quote script  
Line 12: Line 12:
// BEWARE it cannot handle quotes more than 256 characters. Split them into multiple lines if needed.
// BEWARE it cannot handle quotes more than 256 characters. Split them into multiple lines if needed.


// This is a free script, DO NOT RESELL! Feel free to hack it, it's loosely based on the classic dataserver script from the LSL wiki. Feel free to modify it to make your own book! Make code not war <3
// This is a free script, DO NOT RESELL!
// It's loosely based on the classic dataserver script from the LSL wiki.
// Feel free to modify it to make your own book! Make code not war <3


// Globals
string notecardName = "<--the notecard name goes here -->";
integer iNotecardIndex;
 
integer iNotecardCount;
integer currentLine;
integer iNoteCardLine;
key notecardRequestID;
key kCurrentDataRequest;
 
string sData;
integer quoteIndex;
list QUOTE = [];
integer numberOfQuotes;
integer counter = 0;
list listOfQuotes;
string sSettingsNotecard = "_quotes";
 
init()
{
    integer numberOfNotecards = llGetInventoryNumber(INVENTORY_NOTECARD);
 
    if (numberOfNotecards)
    {
        currentLine = 0;
        notecardRequestID = llGetNotecardLine(notecardName, currentLine);
 
        llOwnerSay("Loading notecards now...");
    }
}


default
default
{
{
     on_rez( integer param )
     on_rez(integer start_param)
     {
     {
         llResetScript();
         llResetScript();
     }
     }


     touch_end(integer total_number)
     changed(integer change)
     {
     {
         // integer index = llRound(llFrand(1) * (iNoteCardLine-1));
         if (change & CHANGED_INVENTORY)
        llSay(0,llList2String(QUOTE, counter));
            llResetScript();
        counter++;
    }
       
        if ( counter > (iNoteCardLine-1))  { counter = 0;}


    state_entry()
    {
        init();
     }
     }


     state_entry()
     touch_start(integer num_detected)
     {
     {
         //integer iii;
         llSay(PUBLIC_CHANNEL, llList2String(listOfQuotes, quoteIndex));
       
 
        llOwnerSay("Loading quotes, please wait...");
         if (numberOfQuotes <= ++quoteIndex)
             quoteIndex = 0;
        iNotecardCount = llGetInventoryNumber( INVENTORY_NOTECARD );
 
        iNotecardIndex = 0;
         if( iNotecardCount > iNotecardIndex ) {
   
             iNoteCardLine = 0;
            kCurrentDataRequest = llGetNotecardLine( sSettingsNotecard, iNoteCardLine );
            iNotecardIndex++;
        }
     }
     }


     dataserver( key kQuery, string sData )
     dataserver(key id, string data)
     {
     {
         list lSetting;
         notecardRequestID = NULL_KEY;


        kCurrentDataRequest = "";
         if (data == EOF)
         if( sData != EOF )
         {
         {
                if ( (string)sData == "" ) { return; }
             currentLine = 0;
              
                QUOTE += [(string)sData];


                 kCurrentDataRequest = llGetNotecardLine( sSettingsNotecard, ++iNoteCardLine );
            numberOfQuotes = llGetListLength(listOfQuotes);
            integer freeMemory = llGetFreeMemory();
 
            llOwnerSay("Done loading notecards!\n"
                 + (string)numberOfQuotes + " quotes loaded, free memory " + (string)freeMemory);
         }
         }
         else
         else
         {
         {
            iNotecardIndex++;
             if (data != "")
             if( iNotecardIndex < llGetInventoryNumber( INVENTORY_NOTECARD ) )
                 listOfQuotes += [data];
            {
 
                 iNoteCardLine = 0;
            notecardRequestID = llGetNotecardLine(notecardName, ++currentLine);
                llGetNotecardLine( sSettingsNotecard, iNoteCardLine );
            }
            else
            {
                llOwnerSay("Ready!");
                llOwnerSay((string)iNoteCardLine + " Quotes Loaded");
                llOwnerSay( "FreeMem: " + (string)llGetFreeMemory() );  
            }
         }
         }
    }
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
            llResetScript();
     }
     }
}
}
 
</source>
</lsl>


{{LSLC|Examples}}
{{LSLC|Examples}}
{{LSLC|Library}}
{{LSLC|Library}}

Latest revision as of 02:34, 22 January 2015

This script will deliver quotes sequentially from a notecard when touched.

In the same object you drop this script, create a notecard called "_quotes" and simply put your quotes in it, max. 255 characters per line or they will be truncated. Watch out not to bust the script memory stack by adding too much, but you can use Mono to compile it and create a very long notecard.

// Touch a quote script 
// By CodeBastard Redgrave
// Reads quotes from a notecard and displays them sequentially when you touch!
// BEWARE it cannot handle quotes more than 256 characters. Split them into multiple lines if needed.

// This is a free script, DO NOT RESELL!
// It's loosely based on the classic dataserver script from the LSL wiki.
// Feel free to modify it to make your own book! Make code not war <3

string notecardName = "<--the notecard name goes here -->";

integer currentLine;
key notecardRequestID;

integer quoteIndex;
integer numberOfQuotes;
list listOfQuotes;

init()
{
    integer numberOfNotecards = llGetInventoryNumber(INVENTORY_NOTECARD);

    if (numberOfNotecards)
    {
        currentLine = 0;
        notecardRequestID = llGetNotecardLine(notecardName, currentLine);

        llOwnerSay("Loading notecards now...");
    }
}

default
{
    on_rez(integer start_param)
    {
         llResetScript();
    }

    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
            llResetScript();
    }

    state_entry()
    {
        init();
    }

    touch_start(integer num_detected)
    {
        llSay(PUBLIC_CHANNEL, llList2String(listOfQuotes, quoteIndex));

        if (numberOfQuotes <= ++quoteIndex)
            quoteIndex = 0;

    }

    dataserver(key id, string data)
    {
        notecardRequestID = NULL_KEY;

        if (data == EOF)
        {
            currentLine = 0;

            numberOfQuotes = llGetListLength(listOfQuotes);
            integer freeMemory = llGetFreeMemory();

            llOwnerSay("Done loading notecards!\n"
                + (string)numberOfQuotes + " quotes loaded, free memory " + (string)freeMemory);
        }
        else
        {
            if (data != "")
                listOfQuotes += [data];

            notecardRequestID = llGetNotecardLine(notecardName, ++currentLine);
        }
    }
}