Skip to content

LSL: Notecard Selector

One of my friendly librarian colleagues in SL asked if I had a script to generate dialogs and allow users to select notecards handy. I didn’t, so I coded it up. It seems like it could be useful to others, so here you go:

This script is in LSL, for Second Life. Just copy and paste it into a script, throw a few notecards into the object, and you’ll be ready to go!

//  Notecard Selector
//  by Ann Enigma
//  This script presents users with a list of notecards in a dialog box, and allows them to select one
//  Note: The names of the notecards must be less than 24 characters long

// This script is licenced under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
// http://creativecommons.org/licenses/by-nc-sa/3.0/us/

// configurable options
string message = “Which notecard would you like to read?”; // the message on the dialog box
integer command_channel = 616; // the channel on which to listen for commands (you probably won’t need to change this)

// the script
list notecards;

default
{
    state_entry()
    {
                integer i = 0;
               
                // read the title of each notecard into a list
                for(i=0;i<llGetInventoryNumber(INVENTORY_NOTECARD);i++) {
                        notecards = (notecards=[]) + notecards + [llGetInventoryName(INVENTORY_NOTECARD,i)];
                }
               
                llListen(command_channel, “”, “”, “”); // listen for a dialog button press
    }

    touch_start(integer total_number)
    {
        llDialog(llDetectedKey(0), message, notecards, command_channel); // present the dialog
    }

        listen(integer channel, string name, key id, string message) {
                if (llListFindList(notecards, (list)message) != -1) { // this is a valid notecard
                        llGiveInventory(id, message); // give the user the notecard
                }
        }
       
        changed(integer changed_bitfield) {
                // if the object’s inventory changes, reset the script
                if (changed_bitfield == CHANGED_INVENTORY) {
                        llResetScript();
                }
        }
}

Related posts

{ 6 } Comments

  1. James/Calisto | March 28, 2008 at 2:27 pm | Permalink

    Hi Hilary,

    What a great script! Does this script work if you copy and paste from the post? I tried and got a syntax error at (9, 23).

    Thanks!

    Calisto/James

  2. Hilary | March 29, 2008 at 12:30 am | Permalink

    It looks like the code rendering engine is replacing the double quotes (”) with curly quotes. Just replace them all and it works great.

    -Hilary

  3. Ciaran | April 2, 2008 at 6:14 pm | Permalink

    Thanks for this excellent script - (as mentioned the quotes need to be replaced) :)

  4. Lesya | April 21, 2008 at 3:52 pm | Permalink

    Hi, Hillary:

    Thank you for the wonderful website - learning quite a few things from you. I am terribly sorry, but I am daring to ask you a question as you stand as a SL scripting expert in my eyes. Please, forgive me for taking your time, but your answer will be much appreciated.

    In this one script we need to automatically unlink objects. We have used llbreakalllinks(), llbreaklink and similar. We need to request permissions of the owner and have used llrequespermissions and similar functions. It just doesn’t work. We suspect there is some little trick we just don’t know about.

    Any help will be greatly appreciated!

  5. djmurray | April 29, 2008 at 4:07 pm | Permalink

    eh im getting errors can someone help?

  6. Hilary | June 28, 2008 at 3:20 pm | Permalink

    Hi DJ,

    Did you see the note above about the double-quotes?

    If you’re still getting an error, please comment back and let me know what it is.

    Best,

    Hilary

Post a Comment

Your email is never published nor shared. Required fields are marked *