Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

SubMenus question

Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-25-2009 15:53
These sounds as if it should be easy, but I can't figure it out (which usually means the answer is blindingly obvious).

I want to change the menu buttons in a submenu depending on what message was received when the resident clicked the previous menu. One way to do it is something like
CODE
if (message == "red") 
{
menu_buttons = Reds;
}
else if (message == "blue")
{
menu_buttons = Blues;
}

Reds and Blues are, of course, lists of options I've defined earlier.

I'm wondering, though, if it's possible to define a list of the names of my option button lists and a list of messages I'm going to receive and, at run-time, just look up the list it should be using depending on what the message is.

I can make it look up the appropriate value and say "Reds" when it gets the message, "red", but I can't see how then to get it actually to make menu_buttons = Reds and use that list to generate a menu.

Any suggestions?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-25-2009 17:59
if I understand you're want, you'd like to avoid using a hard coded word to define the sublists when checking the response from the main list?

you can do an ordinal selection, by assigning all the sub lists a defined spot in your main list based on the order in the main list. sorry not making this sound simple but it is...

CODE

//-- in globals
list gLstMain = ["numbers", "letters", "symbols"];
list gLstSub0 = ["1", "2", "3"];
list gLstSub1 = ["a", "b", "c"];
list gLstSub2 = ["!", "@", "#"];


//-- in listen
integer vIndtest = llListFindList( (list)vStrHeard, gLstMain ); //-- here's your trick
if (~vIndTest){
if (vIndTest %2){
//-- use sub1
}else if (vIndTest){
//-- use sub2
}else{
//-- use sub0
}
}


the only real improvement there is that the same code is reusable and modifiable for differing lists or changes.

there are more complex ways to do it involving a huge master list which is done in strides and ranges, and each response is checked by it's index and then (for instance) the next entry contains information on how to respond and is read for what to do... very much like a database record set, but this method is very complex and overkill for simpler projects

a slight simplification would be a single list using index pointers to define what goes out to the dialog, but can get as complicated as above when trying to make it dynamic.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Kerik Rau
Registered User
Join date: 8 Mar 2007
Posts: 54
01-25-2009 18:02
Try storing the list in the global namespace:

list Reds = ["item 1", "item 2"];
list Blues = ["item1", "item 2"];

default
{
...

You can also use += to append new items to the list (which is really handy when dynamically generating menus).

ex.
list Reds = [];
Reds += "Dark Red";
Reds += ["Light Red", "Medium Red"];
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
01-25-2009 18:48
llDialog is always kind of confusing the first time. Here you go Innula:

CODE

list menu_main = ["Reds", "Blues"];
list menu_blue = ["blue1", "blue2", "blue3"];
list menu_red = ["red1", "red2", "red3"];
integer chan_menu = -12312378;
integer listen_handle;
key key_id;

default {
touch_start(integer n) {
key_id = llDetectedKey(0);
llDialog(key_id, "Pick a color", menu_main, chan_menu);
listen_handle = llListen(chan_menu, "", key_id, "");
llSetTimerEvent(30.0);
}
listen(integer channel, string name, key id, string msg) {
if("Reds" == msg){
llDialog(key_id, "Pick a red color", menu_red, chan_menu);
}
else if("Blues" == msg){
llDialog(key_id, "Pick a blue color", menu_blue, chan_menu);
}
else if(~llListFindList(menu_blue,[msg]) || ~llListFindList(menu_red,[msg])){
llSay(0, msg);
llListenRemove(listen_handle);
llSetTimerEvent(0.0);
}
}
timer() {
llListenRemove(listen_handle);
llSetTimerEvent(0.0);
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-26-2009 11:12
Thanks all.

I think Void has answered my question for me, but if I give an example of what I'm trying to do, maybe it will clarify things.

It struck me that, rather than having a load of statements in the listen event about
CODE
if (msg == "this")
{
//do something}
else if (msg == "that")
{
// do something else
}
I can save myself a lot of time in both the short and long term (because it makes the code easier to recycle) by writing something like this:
CODE
list menu_main;
integer chan_menu = -12312378;

list colors = ["red", <1.0, 0.0, 0.0>, "blue", <0.0, 0.0, 1.0>, "green", <0.0, 1.0, 0.0>];



integer listen_handle;
key key_id;

default {
state_entry()
{
menu_main = llList2ListStrided(colors, 0, -1, 2);
}

touch_start(integer n) {
key_id = llDetectedKey(0);
llDialog(key_id, "Pick a color", menu_main, chan_menu);
listen_handle = llListen(chan_menu, "", key_id, "");
llSetTimerEvent(30.0);
}
listen(integer channel, string name, key id, string msg)
{
vector mycolor = llList2Vector(colors, llListFindList(colors,[msg])+1);
llSetColor(mycolor, ALL_SIDES);
}
timer() {
llListenRemove(listen_handle);
llSetTimerEvent(0.0);
}
}
This way, if I want to change or add to my colours, I just have to alter the list, colors.

I was wondering -- and, as I say, I think Void has answered my question for me -- if I could do something similar and somehow have a list of submenus and then look up which one to use, based on the message I receive from the main menu, and not have to have any if statements at all to update.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-26-2009 11:37
the problem with that is llDialog will only display up to 12 buttons at once, so if your color list is longer, you'll get an error. but if you're only doing up to 12, no problem

as far as activating a submenu based on the message from the main, you will need to use if statements
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-26-2009 12:35
From: Ruthven Willenov
the problem with that is llDialog will only display up to 12 buttons at once, so if your color list is longer, you'll get an error. but if you're only doing up to 12, no problem
Yeah, if I left the code as it is, I would have problems but I was just giving a simple example of what I am trying to do. In my actual script I'm using something based on /54/94/235155/1.html#post1836030so it's not a issue... that code is such a useful example.