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!
// 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();
}
}
}
{ 11 } Comments
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
It looks like the code rendering engine is replacing the double quotes (”) with curly quotes. Just replace them all and it works great.
-Hilary
Thanks for this excellent script - (as mentioned the quotes need to be replaced)
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!
eh im getting errors can someone help?
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
I got it to compile correctly, place 3 notecards but it doesn’t do anything on the TOUCH_START event. No Dialog pops up.
Re edit this post with a working one telling people to fix it kind of annoying. and i did the changes noted but still got errors.
It gives me the following error:
Object: llDialog: button labels must be 24 or fewer characters long
I figured it was the crazy characters used in some of the notecards, but changing that did not help.
Ah, figured it out. The titles of all notecards together cant be longer then 24 chars.
Thanks for the great and useful script!
Post a Comment