Jump to content

Multi-Page Dialog Menu w/ Sub-Menu


DarkEmperor13
 Share

You are about to reply to a thread that has been inactive for 1823 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm trying to figure out how to make a multi-page menu with sub menus. 

// Simple Multipage Menu  --  Rolig Loon --  August 2013

// The Menu routine in this script will parse your input list (gNames) into menu pages
//    of 12 buttons each, including a forward button and a back button, as appropriate.
//    It generates a page's buttons on demand, so that the list of button labels is
//    never more than 12 items long.
//    It does NOT trim potential menu items to fit the 25-character limit (or the 
//    12-character display limit), nor does it sort buttons or do other fancy things
//    that you are free to add for yourself.

list gMain = ["Adult","Cuddles"];
list gPoses1 = ["","B","C","D","E","F","G",
       "H","I","J","K","L","M","N","O","P","Q",
       "R","S","T","U","V","W","X","Y"];
list gPoses2 = ["","B","C","D","E","F","G",
       "H","I","J","K","L","M","N","O","P","Q",
       "R","S","T","U","V","W","X","Y"];
list MenuButtons;  // Your list of potential menu choices
integer gMenuPosition;  // Index number of the first button on the current page
integer gLsn;   // Dialog Listen Handle
key UserID;
integer MenuDialogChannel;
integer MenuListenHandle;

Menu0()
{
    
    //Show Menu with selected buttons
     llDialog(llGetOwner()," \n",MenuButtons,-12345);

    //Listen to the menu chanel which menu item the user have chosen
     llListenRemove(MenuListenHandle);
    
    //Assign the listen to a handle so we can kill it when the user don't respond to the menu
     MenuListenHandle = llListen(MenuDialogChannel, "", UserID, "");

    //Set a timer for the time the user has to respond to the menu.
     llSetTimerEvent(30.0);
  
}
Menu1()
{
    integer Last;
    integer All = llGetListLength(gPoses1);
    if(gMenuPosition >= 9)   //This is NOT the first menu page
    {
        MenuButtons += "    <----";
        if((All - gMenuPosition) > 11)  // This is not the last page
        {
            MenuButtons += "    ---->";
        }
        else    // This IS the last page
        {
            Last = TRUE;
        }            
    }    
    else if (All > gMenuPosition+9) // This IS the first page
    {
        if((All - gMenuPosition) > 11)  // There are more pages to follow
        {
            MenuButtons += "    ---->";
        }
        else    // This IS the last page
        {
            Last = TRUE;
        }            
    }
    else    // This is the only menu page
    {
        Last = TRUE;
    }
    if (All > 0)
    {
        integer b;
        integer len = llGetListLength(MenuButtons);
        // This bizarre test does the important work ......        
        for(b = gMenuPosition + len + Last - 1 ; (len < 12)&&(b < All); ++b)
        {
            MenuButtons = MenuButtons + [llList2String(gPoses1,b)];
            len = llGetListLength(MenuButtons);
        }
    }
    gLsn = llListen(-12345,"","","");    
    llSetTimerEvent(10.0);
    llDialog(llGetOwner()," \n",MenuButtons,-12345);
}
Menu2()
{
    integer Last;
    integer All = llGetListLength(gPoses2);
    if(gMenuPosition >= 9)   //This is NOT the first menu page
    {
        MenuButtons += "    <----";
        if((All - gMenuPosition) > 11)  // This is not the last page
        {
            MenuButtons += "    ---->";
        }
        else    // This IS the last page
        {
            Last = TRUE;
        }            
    }    
    else if (All > gMenuPosition+9) // This IS the first page
    {
        if((All - gMenuPosition) > 11)  // There are more pages to follow
        {
            MenuButtons += "    ---->";
        }
        else    // This IS the last page
        {
            Last = TRUE;
        }            
    }
    else    // This is the only menu page
    {
        Last = TRUE;
    }
    if (All > 0)
    {
        integer b;
        integer len = llGetListLength(MenuButtons);
        // This bizarre test does the important work ......        
        for(b = gMenuPosition + len + Last - 1 ; (len < 12)&&(b < All); ++b)
        {
            MenuButtons = MenuButtons + [llList2String(gPoses2,b)];
            len = llGetListLength(MenuButtons);
        }
    }
    gLsn = llListen(-12345,"","","");    
    llSetTimerEvent(10.0);
    llDialog(llGetOwner()," \n",MenuButtons,-12345);
    }

default
{
    touch_start(integer num_detected)
    {
        llListenRemove(gLsn);
        gMenuPosition = 0;
        MenuButtons = gMain;
        Menu0();
    }
        
    
    listen(integer channel, string name, key id, string msg)
    {
        llListenRemove(gLsn);
        llSetTimerEvent(0.0);
        if(~llListFindList(gMain,[msg]))
        {
            if (msg == "Adult")
            {
                MenuButtons = gPoses1;
                Menu1();
            }
            else if (msg == "Cuddles")
            {
                MenuButtons = gPoses2;
                Menu2();
            }
        }
        else
        {
            if (msg == "Back")
            {
                MenuButtons = gMain;
                Menu0();
                return;
            }
            if(~llSubStringIndex(msg,"---->"))
            {
                gMenuPosition += 10;
                Menu1();
            }
            else if (~llSubStringIndex(msg,"<----"))
            {
                gMenuPosition -= 10;
                Menu1();
            }
            else
            {
            //Do whatever the selected button directs..... your choice
        }
    }
    }
    
    timer()
    {
        llSetTimerEvent(0.0);
        llListenRemove(gLsn);
    }
}

But as u can see, i'm totally stumped. Could someone give me an example using one main and one sub? 

Link to comment
Share on other sites

First, do NOT start with someone else script.  Start writing yours from the ground up.  You'll never understand it otherwise.  A multipage menu is itself a difficult thing to wrap your head around.  Doing it within submenus is another complication.

Second, as you do write your own script do it in modular style.  Get the nested submenus working first.  They are your highest level in the logic.  Once you have them working, then go back and add a multipage system to each of the submenus as appropriate  -- and worry about keeping them separate so that you don't jump from one submenu to another by mistake.

Frankly, this is going to make your head hurt.  The logic here is something that nobody can map out for you.  You simply have to sit down and bang on it until it makes sense.

 

  • Thanks 1
Link to comment
Share on other sites

Second what Rolig said... But here's a couple of thoughts to get you started.

Branching menu systems are memory-hungry. Think about putting your menu in a separate script to your "functional code".  Your functional code then needs to worry about only two things. Kicking off the process with "Hey, this guy's using the menu" and getting a response back. The only responses that need to be sent are the endpoints of your menu system (including "menu timeout") - your functional code doesn't need to know whether the command to "Do McGuffin" was selected from the main menu or from page 3 of a nested-4-deep submenu.

Secondly, remember that a 'submenu" and "another page of the same menu" really aren't that different. You display another menu with different options. 

Coming up with a design that uses a somewhat generic "DoMenu( ... )" subroutine which takes care of populating the text and option lists, establishing the listener, setting a timestamp for checking timeouts, making sure a timer is running to check for timeouts and finally making the llDialog() call will save you a LOT of brain-ache down the road. If the result of a menu selection is an endpoint, notify the main script and clear down all menu handling because you're done. If the result requires a fresh menu, whether a different page of the same one, a submenu or a return to a higher level that's just a fresh call to your DoMenu() function with different parameters.

There's LOTS of ways to design it and unless you come up with something really weird you're not going to see much difference in efficiency one way or the other, so the one that is right for you is the one that you can get your head around and keep straight in your mind the easiest. Remember that you're going to have to maintain this code as well as write it!

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Da5id Weatherwax said:

Branching menu systems are memory-hungry. .Think about putting your menu in a separate script to your "functional code".

you're going to have to maintain this code

' Branching menu systems are memory-hungry. ' uses no more memory than a single list. Was the case pre Mono.  'memory-hungry. ' are caused by inefficient script structuring.

If code maintaince is needed after being tested then the code is poorly written. Only thing i do after my code is released is use it as a base for something else, or add something a client requested. Last thing i need is clients being uptight because of code faults. Was the reason i started writting code, I got sick and tired of the garbage so called experts produced.

As for using secondry scripts for lists, you do that as a last resort because the data passing can cause issues if not done correctly.

Link to comment
Share on other sites

2 hours ago, steph Arnott said:

If code maintaince is needed after being tested then the code is poorly written. Only thing i do after my code is released is use it as a base for something else, or add something a client requested

 code maintenance does actually mean adding things to the codebase that clients request. Code maintenance literally means rewriting parts of the codebase to accommodate the new things added

  • Like 1
Link to comment
Share on other sites

33 minutes ago, Mollymews said:

 code maintenance does actually mean adding things to the codebase that clients request. Code maintenance literally means rewriting parts of the codebase to accommodate the new things added

'Code maintenance' is correcting faults and/or improving performance. In short not written well in the first place. That is why testing is done before release. Adding  code is a modification that was never in the code in the first place. Very few in SL write code which does not glitch, most rush it out and then blame the client for the faults and/or the sim server. The issues are never their fault. This is only LSL.

Edited by steph Arnott
Link to comment
Share on other sites

when software comes out of beta and goes to release then it's all maintenance thereafter

LL and SL yes.  The LL team maintain the SL codebase, which includes adding new features and rewriting parts of the codebase to accommodate the changes. In the adding of new features, this can include substantial rewrites to improve performance due not only to client requests, but can also include new hardware availability, new algorithms not previously invented, new operating systems, new hosting platforms, new client connectively devices, etc

i accept that at this stage in your development as a scripter you are pretty enthusiastic, as are most self=taught scripters. All going well then in time you will grow your ability to gain a place on a professional programming team. At which time you will know what it means when Da5id says "you're going to have to maintain this code as well as write it"

"as well as write it" means develop the codebase from scratch.  Maintain means to support the codebase for all of the above reasons, after it has been released

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

2 hours ago, Mollymews said:

 

What has any of that got to do with writting code in LSL? And no you are not going to gain a place on any professional team knowing LSL. LSL is ancient, klunky and outdated. Lua crushes it into the dirt.

Edited by steph Arnott
Link to comment
Share on other sites

You do love to "knock", don't you, Steph? As this is the second time in short successsion you've contradicted me on rather questionable grounds, on widely separate subjects, I've taken the liberty of looking back through your posting history and I haven't found any sign you've got much good to say about anyone else's input, only a long string of contrarian views.


This time, like the last, you are talking complete rubbish.


Like something being "memory hungry" is somehow less of a concern when you've got four times the memory to spare post-mono than before. It still uses the same amount and the goal should be to use as little as possible, don't you think? "No more than a single list" -  that's like saying "no more than the stack" or "no more than the heap" - the data required is the data required whatever structure you organize it into. Or are you saying that addressing the same amount of data differently somehow makes it consume more or less space?


Not having an eye towards maintaining your code? And then dissing somebody who calls you on it because LSL is not a language used in mainstream scripting? Please. I've fired people with that attitude off teams I was leading more than once over the last 35 years. Sooner or later a charlatan always exposes themselves, often by attitude.


Last time we disagreed you claimed to be a law graduate to add authority to statements completely at variance with how the law is applied in a particular area of IT - statements that anyone who had worked in the industry would know were patently false.


What are you going to be this time to support sounding like somebody who barely - and recently at that - passed CompSci 101? The genius hacker who can cpio sunshine out their own /dev/null?

Edited by Da5id Weatherwax
fix typo
  • Like 2
  • Haha 1
Link to comment
Share on other sites

2 hours ago, Da5id Weatherwax said:

 

Knock? You talk about LSL as if it is not a library based top down, cut down basic scripting language.

'Like something being "memory hungry" is somehow less of a concern when you've got four times the memory to spare post-mono than before' that is drivel. Mono was set at 64k because some LSO used four time more memory when converted to mono. Mono uses double memory than 80% of LSO scripts. Mono was implimented because the asset scripts can be shared by multiple objects where as LSO did not.

' no, you claimed that LSL was open source and client written code was the clients copywrite. I stated that LSL is the copywrite property of Linden Research and as such any code using their library created code belongs to LR inc.

The rest of your comments are basically ignorance. As for fireing me, you have never owned any company. I own seven, two in Japan.

Edited by steph Arnott
Link to comment
Share on other sites

7 hours ago, steph Arnott said:

What has any of that got to do with writting code in LSL? And no you are not going to gain a place on any professional team knowing LSL

this is actually not true. Full-time real world staff positions as LSL scripters are advertised and filled from time to time. Typically the successful candidates for these jobs, also have experience with http connectivity  - are also able to develop and maintain the complementary server-side codebase

it is good that you are also getting into other language environments like Lua. The broader our experiences, the more opportunities there are to grow our knowledge and skills, and the wider our life and career path choices become  

Link to comment
Share on other sites

2 minutes ago, Mollymews said:

this is actually not true. Full-time real world staff positions as LSL scripters are advertised and filled from time to time. Typically the successful candidates for these jobs, also have experience with http connectivity  - are also able to develop and maintain the complementary server-side codebase

it is good that you are also getting into other language environments like Lua. The broader our experiences, the more opportunities there are to grow our knowledge and skills, and the wider our life and career path choices become  

No LSL scripter has the skills to write real code. Rollig does. I do not and you certainly do not. BTW SL is not my life, scripting is nothing more than a logic puzzle to me. As for Lua i was writting code in that seven years ago.

Link to comment
Share on other sites

9 minutes ago, steph Arnott said:

Sorry but i see nothing you have produced. The one i did release to the marketplace i was pushed into.

this did make me laugh a little bit. Comparing your 1-only product release to my 0-only product release. The engagement between enthusiastic amateurs can get quite fierce sometimes :)

Link to comment
Share on other sites

Just now, Mollymews said:

this did make me laugh a little bit. Comparing your 1-only product release to my 0-only product release. The engagement between enthusiastic amateurs can get quite fierce sometimes :)

Pal i have over a hundred. I stated i was pushed into releasing that one. And the proceeds go to child poverty. Am not interested in your one upmanship. I see nothing you have produced. It is a simple as that. Good day.

Link to comment
Share on other sites

Just now, steph Arnott said:

Well i write code and build for groups who use it, and i do it for free. So you carry on because i see no evidence you have produced anything in SL..

ah! then we are the same, we both do what we do for free. When anyone asks us how might they do whatever they are wanting, then we do what we can to help as best we can

Link to comment
Share on other sites

1 minute ago, Mollymews said:

ah! then we are the same, we both do what we do for free. When anyone asks us how might they do whatever they are wanting, then we do what we can to help as best we can

Stil have not seen any of your own written code. You keep posting but nothing code wise.

Link to comment
Share on other sites

15 minutes ago, steph Arnott said:

Stil have not seen any of your own written code. You keep posting but nothing code wise.

my product is posted code. Code that shows how algorithms can be implemented in LSL, in those cases where how to approach the algorithm may not always be immediately apparent to every reader. I refer you again to the thread I linked to previously

if you have time to make code contributions to this thread then it would be welcomed 

Link to comment
Share on other sites

1 minute ago, Mollymews said:

my product is posted code. Code that shows how algorithms can be implemented in LSL, in those cases where how to approach the algorithm may not always be immediately apparent to every reader. I refer you again to the thread I linked to previously

if you have time to make code contributions to this thread then it would be welcomed 

So in short nothing. Okay. Also FYI i used to write whole scripts here years ago. Now i do not and niether do anyone else.

Link to comment
Share on other sites

4 minutes ago, steph Arnott said:

So in short nothing. Okay. Also FYI i used to write whole scripts here years ago. Now i do not and niether do anyone else.

i could point to quite a few complete LSL Library scripts on here that I have written on previous accounts, down the years, covering a range of fairly uncommon topics that only a tiny handful of people will ever want or need to implement. Code topics without which their intended application will not see the light of day. Topics with posted code, not only on this forum, but also on the old SL forums, and across the street. But how would pointing to any of these now, serve any of us

this forum is about people looking for answers to their questions. Questions overwhelmingly asked are: How to identify the algorithm needed?. What knowledge is  needed to be gained from the wiki? And when the wiki is silent, then how might they approach those algorithms and what options are available to them

the thread I linked to is about algorithms. And again I invite you to contribute to that thread, so that you can help other scripters to better understand algorithmically what it is they are asking

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1823 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...