Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dialogue Box Help

Claire Glitterbuck
First Life Dodger
Join date: 26 Dec 2004
Posts: 113
12-19-2006 06:07
Be gentle, this is my first time posting here. :D

I'm not a scripter, but I can muddle through simple stuff. I wanted to create a dialogue box for an object that will dispense drinks. I found an example for dialogue boxes on the Wiki, and adapted that a little. It works, to a point ... I get the confirmation message that I picked the option for Bottle of Beer,, and I also get the test message that I added so that I know it's reading everything - however, it does NOT give me the Bottle of Beer, even though it's in the object's inventory (with full perms) - and it also does not give me an error message, so I have no idea what I'm doing wrong. Help please?

Here is the script, I marked the part that I added. Thanks much!

-Claire

// when touched, present a dialog with four color choices

integer CHANNEL = 42; // dialog channel
list MENU_MAIN = ["Bottle of Beer", "Stand", "Fly", "Cheat", "Options..."]; // the main menu
list MENU_OPTIONS = ["Cherry", "Blueberry", "Vinegar", "Slime", "Chips", "Salad", "...Back"]; // a submenu

default {
state_entry() {
llListen(CHANNEL, "", NULL_KEY, "";); // listen for dialog answers (from multiple users)
}

touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "What do you want to do?", MENU_MAIN, CHANNEL); // present dialog on click
}

listen(integer channel, string name, key id, string message)
{
if (llListFindList(MENU_MAIN + MENU_OPTIONS, [message]) != -1) // verify dialog choice
{
llSay(0, name + " picked the option '" + message + "'.";); // output the answer
if (message == "Options...";)
llDialog(id, "Pick an option!", MENU_OPTIONS, CHANNEL); // present submenu on request
else if (message == "...Back";)
llDialog(id, "What do you want to do?", MENU_MAIN, CHANNEL); // present main menu on request to go back
// here you have the name and key of the user and can easily verify if they have the permission to use that option or not
else if (message == "Sit";)
llSay(0, "This is where stuff would happen if this wasn't just an example";);
// My addition
else if (message == "Bottle of Beer";)
llSay(0, "You picked a bottle of beer.";);
llGiveInventory(llDetectedKey(0), "Beer Bottle";);
llSay(0, "Pffft";);
// End of my addition
} else
llSay(0, name + " picked invalid option '" + llToLower(message) + "'.";); // not a valid dialog choice
}
}
_____________________
Nobody ever really changes, they just become more fully themselves.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-19-2006 07:14
I suggest you look at this thread for a better example.

But to answer your question.
You cannot use llDetectedKey(0) inside the listen event, use the id passed in.
You will also need braces around the three related lines or you would give anyone a beer who selected anything.

As an aside please use PHP tags when posting code, makes it easier for us to read.

CODE

// My addition
else if (message == "Bottle of Beer")
{
llSay(0, "You picked a bottle of beer.");
llGiveInventory(id, "Beer Bottle");
llSay(0, "Pffft");
}
// End of my addition
Claire Glitterbuck
First Life Dodger
Join date: 26 Dec 2004
Posts: 113
Thank you!
12-19-2006 09:12
Thank you SO much, that worked like a charm! And sorry about the tags, I'll remember next time! :)

-Claire the Happy Camper
_____________________
Nobody ever really changes, they just become more fully themselves.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-19-2006 11:16
From: Claire Glitterbuck
Thank you SO much, that worked like a charm! And sorry about the tags, I'll remember next time! :)

-Claire the Happy Camper


Your welcome but as I said that script is a really poor example.
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
12-19-2006 11:55
And next time you post code, put it inside "php" tags, like below only use square brackets instead of curly braces:

{php}
your code here
{/php}

That'll cause it to honor the indentation, and it'll even color code the script according to syntax rules. Whee. :)
Trevor Langdon
Second Life Resident
Join date: 20 Oct 2004
Posts: 149
12-19-2006 13:25
And Claire--

To see how the PHP tags (mentioned above) change your post, simply Edit your original post and add the PHP tags. No need to wait for your next post :)