TechplexEngineer
6/23/2014 - 5:07 PM

Ann Enigma's Notecard Selector

Ann Enigma's Notecard Selector

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