Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with Menu Script

Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-26-2007 15:08
I am not sure why I am having trouble with the following script.
Basically I think I am missing something simple here. The menu comes up no problem but then the item never gets given to me for some reason. I have had success with a simple no menu system but I would like to create a simple menu that allows me to give assorted items to people.

Eventually I would like to incorporate a cost for each item as well.

Any help would greatly be appreciated as I am new to the scripting and I can not find anything listed that helped.

Thanks in advance

-----------------------------------------------------
Script Begins Below
-----------------------------------------------------


integer handle;
default
{
touch_start(integer num)
{
handle = llListen(45, "", NULL_KEY, "";);
llDialog(llDetectedKey(0), "What Would You Like To Eat?", ["Doritos", "Sandwich", "Pringles", "Burrito"], 45);
llSetTimerEvent(30);
}
listen(integer channel, string name, key id, string message)
{
llListenRemove(handle);
llSetTimerEvent(0);
if(message == "Doritos";)
llGiveInventory(llDetectedKey(0),"doritos";);
if(message == "Sandwich";)
llGiveInventory(llDetectedKey(0),"Sandwich";);
if(message == "Burrito";)
llGiveInventory(llDetectedKey(0),"Burrito";);
if(message == "Pringles";)
llGiveInventory(llDetectedKey(0),"Pringles";);
}
timer()
{
llListenRemove(handle);
llSetTimerEvent(0);
llWhisper(0, "Menu timeout.";);
}
}


-----------------------------------------------------
Script Ends Above
-----------------------------------------------------
Destiny Niles
Registered User
Join date: 23 Aug 2006
Posts: 949
03-26-2007 15:25
Rewritten code: (I leave it to others to explain your errors)

CODE

integer handle;
default
{
touch_start(integer num)
{
llListen(45, "", NULL_KEY, "");
llDialog(llDetectedKey(0), "What Would You Like To Eat?", ["Doritos", "Sandwich", "Pringles", "Burrito"], 45);
llSetTimerEvent(30);
}

listen(integer channel, string name, key id, string message)
{
if(message == "Doritos")
{
llGiveInventory(llDetectedKey(0),"doritos");
}
else if(message == "Sandwich")
{
llGiveInventory(llDetectedKey(0),"Sandwich");
}
else if(message == "Burrito")
{
llGiveInventory(llDetectedKey(0),"Burrito");
}
else if(message == "Pringles")
{
llGiveInventory(llDetectedKey(0),"Pringles");
}
llListenRemove(handle);
llSetTimerEvent(0);
}

timer()
{
llListenRemove(handle);
llSetTimerEvent(0);
llWhisper(0, "Menu timeout.");
}
}


Hopefully I got all the brackets to match since I'm not in-world to check it out.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-26-2007 15:42
Sorry Destiny but you're not quite right either.
llDetected functions dont work inside a listen, use the passed in key called id instead.
Personally I prefer list look ups to if statements

CODE

list Menu = ["Doritos", "Sandwich", "Pringles", "Burrito"]; // menu Text
list Items = ["doritos", "Sandwich", "Pringles", "Burrito"];// Inventory object names
integer handle;
default
{
touch_start(integer num)
{
key id = llDetectedKey(0);
handle = llListen(45, "", id, "");
llDialog(id, "What Would You Like To Eat?", Menu, 45);
llSetTimerEvent(30);
}
listen(integer channel, string name, key id, string message)
{
llListenRemove(handle);
llSetTimerEvent(0);
integer index = llListFindList(Menu, [ message]);
if(index >= 0) llGiveInventory(id, llList2String(Items, index));
}
timer()
{
llListenRemove(handle);
llSetTimerEvent(0);
llWhisper(0, "Menu timeout.");
}
}
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-27-2007 07:19
Wow Newgate that worked great thanks!
Are list lookups more efficient?

Thats so much simpler than I thought it would be.
As usual I was trying to make it more difficult.

Thanks to all for your guidance.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-27-2007 07:49
From: Dioxide DeSantis
Wow Newgate that worked great thanks!
Are list lookups more efficient?

Thats so much simpler than I thought it would be.
As usual I was trying to make it more difficult.

Thanks to all for your guidance.


List look ups are relativley slow but compared with multiple string compares they are quick. They also reduce the code although they obviously add to the memory required.
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-27-2007 08:13
From: Newgate Ludd
List look ups are relativley slow but compared with multiple string compares they are quick. They also reduce the code although they obviously add to the memory required.


I would guess that the memory requirements are minimal unless the inventory of the item is high?
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-27-2007 11:37
So now if I wanted to add a sub menu to this I would add the following right?
But how would I specify the items for the sub menu?


list MENU_OPTIONS = ["Cherry", "Blueberry", "Vinegar", "Slime", "Chips", "Salad", "...Back"]; // a submenu
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-27-2007 12:53
From: Dioxide DeSantis
So now if I wanted to add a sub menu to this I would add the following right?
But how would I specify the items for the sub menu?


list MENU_OPTIONS = ["Cherry", "Blueberry", "Vinegar", "Slime", "Chips", "Salad", "...Back"]; // a submenu


There are numerous ways to handle adding additional menu options and sub menu's.
A lot of it comes down to how you personally like to write code.

The easiest way is to define a new list to handle the sub menu, and then in the listen event display the new menu when required. The draw back is that you end up with more special cases each time you add new sub menu's.

Another appraoch, more complex but more easily reuseable, is to define the menu contents and sub menu's in different lists or to use some form of pre or post fix character to identify sub menu's and then pass processing to different methods based on the options.
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-27-2007 13:40
From: Newgate Ludd
There are numerous ways to handle adding additional menu options and sub menu's.
A lot of it comes down to how you personally like to write code.

The easiest way is to define a new list to handle the sub menu, and then in the listen event display the new menu when required. The draw back is that you end up with more special cases each time you add new sub menu's.

Another appraoch, more complex but more easily reuseable, is to define the menu contents and sub menu's in different lists or to use some form of pre or post fix character to identify sub menu's and then pass processing to different methods based on the options.


So then I would just add another list like

list Menu_2 = ["Item 1", "Item 2";); // menu Text
list Items = ["Item 1", "Item 2"];// Inventory

Would that work?
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-27-2007 13:42
Sorry for all the questions but I am learning alot :)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-28-2007 00:11
From: Dioxide DeSantis
Sorry for all the questions but I am learning alot :)


Thats what this forum is for.
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-28-2007 07:49
Ok here is what i have thus far.
But it places everything on the same menu not separate ones?

CODE


list Menu = ["Doritos", "Sandwich", "Pringles", "Burrito"]; // menu Text
list Items = ["doritos", "Sandwich", "Pringles", "Burrito"];// Inventory object names
list Menu_2 = ["Item 1", "Item 2"); // menu Text
list Items_2 = ["Item 1", "Item 2"]; // Inventory
integer handle;
default
{
touch_start(integer num)
{
key id = llDetectedKey(0);
handle = llListen(45, "", id, "");
llDialog(id, "What Would You Like To Eat?", Menu + Menu_2, 45);
llSetTimerEvent(30);
}
listen(integer channel, string name, key id, string message)
{
llListenRemove(handle);
llSetTimerEvent(0);
integer index = llListFindList(Menu + Menu_2, [ message]);
if(index >= 0) llGiveInventory(id, llList2String(Items + Items_2, index));
}
timer()
{
llListenRemove(handle);
llSetTimerEvent(0);
llWhisper(0, "Menu timeout.");
}
}

Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-28-2007 11:44
From: Dioxide DeSantis
Ok here is what i have thus far.
But it places everything on the same menu not separate ones?




Because you told it to.You said "show me a dialog with buttons from menu1 and menu2".
It is up to you as the scripter to decide what constitutes the hierarchy, LSL just supplies a mechanism to manipulate it.

Consider the following

CODE

list MainMenu = [ "Snack" , "Drink" ];
list SnacksMenu = ["Doritos", "Sandwich", "Pringles", "Burrito"]; // menu Text
list SnackItems = ["doritos", "Sandwich", "Pringles", "Burrito"];// Inventory object names
list DrinksMenu = ["Beer", "Cola", "Tea"]; // menu Text
list DrinkItems = ["beer", "coke", "tea"];// Inventory object names

integer Listening;
integer Channel;

// --------------------------
UpdateListen(key id)
{
CancelListen();
Channel = 0 - (integer)llFrand(2147483647);
Listening = llListen(Channel,"",id,"");
llSetTimerEvent(20);
}
// --------------------------
CancelListen()
{
if(Listening > 0) llListenRemove(Listening);
Listening = 0;
llSetTimerEvent(0);
}
// --------------------------
ShowMainMenu(key id)
{
UpdateListen(id);
llDialog(id, "What Would You Like?", MainMenu, Channel);
}
// --------------------------
ShowSnacksMenu(key id)
{
UpdateListen(id);
llDialog(id, "What Would You Like To Eat?", SnacksMenu, Channel);
}
// --------------------------
ShowDrinksMenu(key id)
{
UpdateListen(id);
llDialog(id, "What Would You Like To Drink?", DrinksMenu, Channel);
}
// --------------------------
default
{
touch_start(integer num)
{
key id = llDetectedKey(0);
ShowMainMenu(id);
}

listen(integer channel, string name, key id, string message)
{
CancelListen();
llSetTimerEvent(0);
integer index = llListFindList(MainMenu, [ message]);
if(0 == index)
ShowSnacksMenu(id);
else if(1 == index)
ShowDrinksMenu(id);
else
{
index = llListFindList(SnacksMenu, [ message]);
if(index >= 0)
{
llGiveInventory(id, llList2String(SnackItems, index));
}
else
{
index = llListFindList(DrinksMenu, [ message]);
if(index >= 0) llGiveInventory(id, llList2String(DrinkItems, index));
}
}
}

timer()
{
CancelListen();
}
}
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-28-2007 20:54
Ah now I see how you did it.

With this type of script I could very easily edit it for different items

Thank you very much for your help.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-29-2007 04:38
From: Dioxide DeSantis
Ah now I see how you did it.

With this type of script I could very easily edit it for different items

Thank you very much for your help.



You can but that becomes more and more labourious as you add more items.
This is the point where use of notecards and a menuing system should be considered.
Have a read of this thread for a few more ideas and details.
Jennifer Simoni
Registered User
Join date: 27 Jan 2007
Posts: 3
List Item (Name Length)
04-22-2007 19:13
Is there a way to make the button names longer?

For example: using "Chocolate Chip" in the list instead of "Cookie" to be more descriptive.

Also, is there a way to name the inventory item in the script so it allows spaces, or do I need to use underscores. (would prefer not to, if possible).

I'm using the give item script from this thread, and am having trouble with modifications/customizations. :(

Thanks!!!
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-23-2007 00:03
From: Jennifer Simoni
Is there a way to make the button names longer?

For example: using "Chocolate Chip" in the list instead of "Cookie" to be more descriptive.

Also, is there a way to name the inventory item in the script so it allows spaces, or do I need to use underscores. (would prefer not to, if possible).

I'm using the give item script from this thread, and am having trouble with modifications/customizations. :(

Thanks!!!



llDialog allows upto 24 characters per button but will generally only display the first 10 or 12. A compromise is to display the description as string above the button rather than on it. This allows for approx 35 characters. However there is only room for 4 or 5 lines of text above the buttons beofre you need to scroll.

Spaces are allowed in names without problem.
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
04-23-2007 00:24
you've probably thought of this.. but "Choc-Chip" would fit.
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura
Jennifer Simoni
Registered User
Join date: 27 Jan 2007
Posts: 3
Choc Chip
04-24-2007 16:25
Thanks Newgate! And, yes, Winter... I did end up using that. :)

Now, does anyone know if there is a way to allow spaces in the actual inventory item name?

For example: chocolate chip cookie

rather than: chocolate_chip_cookie

I do have a couple things that give items with spaces in the names, but the scripts in them are "no mod", so I can't look to it for an example.

I did notice that I can use spaces in the list Menu part, but now, it's the list Items I'm having trouble with.

Any help is appreciated!

Jennifer
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
04-24-2007 17:47
As long as it is inside the double quotation marks, a space is just like any other letter or number digit.
Jennifer Simoni
Registered User
Join date: 27 Jan 2007
Posts: 3
Well, I'll be darned!
04-24-2007 17:59
Thanks! I must have had an extra space in there somewhere, because I couldn't get it to work for the life of me, before. Walking away and coming back to something sure helps.

I appreciate the response and how helpful everyone is on these forums. It sure makes the learning process more enjoyable!

Jennifer