You are currently in the Forum Archive. All content within this area is Read-Only and cannot be modified. Active Forums can be found here.
Reply
New Resident
Thaleenin Sydney
Posts: 3

multi level animation menu demo with exit and back and help

Took code from all over and made this work.  It's well commented so should be a good menu learning tool.

And sorry I cant remember who I borrowed what from


enjoy


// multi level animation menu demo with exit and back and help.lsl
//
// modified  by Thaleenin Sydney
//
integer channel;                                // channel that we are listening on
integer listener;                               // internal number representing the listener
key agentKey;                                   // persons key who is using menu
string agentName;                               // person who is using menu
float timeout = 999;                            // number of seconds before dialogs time out
string menu = "";                               // current menu being displayed to user
list mainButtons = ;    // first menu   start of menu buttons list
list main1Buttons = ;    // main1 menu
list main2Buttons = ; // main2 menu
list main3Buttons = ; // main3 menu
list main4Buttons = ; // main4 menu   end of menu buttons list
init()                                          // start of stop listening
{
    stopListening();
}
//
stopListening()

    if(listener != 0)
    {
        llListenRemove(listener);
        listener = 0;
    }                                           // end of stop listening
    menu = "";                                  // set to main menu
    agentKey = NULL_KEY;                        // start of forget current user
    agentName = "";
    channel = 0;                                // end of forget current user
    llSetTimerEvent(0);                         // stop timing out
}
mainMenuHandler(string message)
{
    menu = message;
   
    if(message == "main1")
        llDialog(agentKey, "\n \n                              main1 Menu\n \n Select your choice", main1Buttons, channel);
    else if(message == "main2")
        llDialog(agentKey, "\n \n                              main2 Menu\n \n Select your choice", main2Buttons, channel);
    else if(message == "main3")
        llDialog(agentKey, "\n \n                              main3 Menu\n \n Select your choice", main3Buttons, channel);
    else if(message == "main4")
        llDialog(agentKey, "\n \n                              main4 Menu\n \n Select your choice", main4Buttons, channel);
    else
    {
        llInstantMessage(agentKey, "Unknown menu item - " + message);
        stopListening();
        return;
    }
    llSetTimerEvent(timeout);                   // extend timeout
}
main1MenuHandler(string message)
{
   if (message == "Exit")
{  
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
    stopListening();                            // stop script and close menu
}
    else  if(message == "1")
    {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance1");     // start 1 animation
        llDialog(agentKey, "\n \n                              main1 Menu\n \n Select your choice", main1Buttons, channel);
    }
     else  if(message == "2")
    {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance2");     // start 2 animation
        llDialog(agentKey, "\n \n                              main1 Menu\n \n Select your choice", main1Buttons, channel);               
    }               
     else  if(message == "3")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance3");     // start 3 animation                           
        llDialog(agentKey, "\n \n                              main1 Menu\n \n Select your choice", main1Buttons, channel);
    }
     else  if(message == "Help")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
        llGiveInventory(agentKey, "helpfile.txt");
        llDialog(agentKey, "\n \n                              main1 Menu\n \n Select your choice", main1Buttons, channel);
    }
     else  if(message == "Previous")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
        menu = "";                              // set menu to default
        llDialog(agentKey, "\n \n                              main1 Menu\n \n Select your choice", mainButtons, channel);
    }
}
main2MenuHandler(string message)
{
   if (message == "Exit")
{  
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
    stopListening();                            // stop script and close menu
}
    else  if(message == "1a")
    {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations;
                llStartAnimation("dance1");     // start 1a animation
        llDialog(agentKey, "\n \n                              main2 Menu\n \n Select your choice", main2Buttons, channel);               
}
     else  if(message == "2a")
    {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance2");     // start 2a animation
        llDialog(agentKey, "\n \n                              main2 Menu\n \n Select your choice", main2Buttons, channel);                
}               
     else  if(message == "3a")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance3");     // start Back of Head animation                           

        llDialog(agentKey, "\n \n                              main2 Menu\n \n Select your choice", main2Buttons, channel); 
    }
     else  if(message == "Help")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
        llGiveInventory(agentKey, "helpfile.txt");
        llDialog(agentKey, "\n \n                              main2 Menu\n \n Select your choice", main2Buttons, channel);
    }
     else  if(message == "Previous")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations;
        menu = "";                              // set menu to default
        llDialog(agentKey, "\n \n                              main1 Menu\n \n Select your choice", mainButtons, channel);
    }
}
main3MenuHandler(string message)
{
   if (message == "Exit")
{  
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
    stopListening();                            // stop script and close menu
}
    else  if(message == "1b")
    {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance1");     // start 1a animation
        llDialog(agentKey, "\n \n                              main3 Menu\n \n Select your choice", main3Buttons, channel);               
}
     else  if(message == "2b")
    {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance2");     // start 2a animation
        llDialog(agentKey, "\n \n                              main3 Menu\n \n Select your choice", main3Buttons, channel);                
}               
     else  if(message == "3b")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance3");     // start Back of Head animation                           

        llDialog(agentKey, "\n \n                              main3 Menu\n \n Select your choice", main3Buttons, channel); 
    }
     else  if(message == "Help")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
        llGiveInventory(agentKey, "helpfile.txt");
        llDialog(agentKey, "\n \n                              main3 Menu\n \n Select your choice", main3Buttons, channel);
    }
     else  if(message == "Previous")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
        menu = "";                              // set menu to default
        llDialog(agentKey, "\n \n                              main1 Menu\n \n Select your choice", mainButtons, channel);
    }
}
main4MenuHandler(string message)
{
   if (message == "Exit")
{  
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
    stopListening();                            // stop script and close menu
}
    else  if(message == "1c")
    {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance1");     // start 1a animation
        llDialog(agentKey, "\n \n                              main4 Menu\n \n Select your choice", main4Buttons, channel);               
}
     else  if(message == "2c")
    {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance2");     // start 2a animation
        llDialog(agentKey, "\n \n                              main4 Menu\n \n Select your choice", main4Buttons, channel);                
}               
     else  if(message == "3c")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
                llStartAnimation("dance3");     // start Back of Head animation                           

        llDialog(agentKey, "\n \n                              main4 Menu\n \n Select your choice", main4Buttons, channel); 
    }
     else  if(message == "Help")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
        llGiveInventory(agentKey, "helpfile.txt");
        llDialog(agentKey, "\n \n                              main4 Menu\n \n Select your choice", main4Buttons, channel);
    }
     else  if(message == "Previous")
         {
                llStopAnimation("dance1");      // start of stop all animations
                llStopAnimation("dance2");
                llStopAnimation("dance3");
                llStopAnimation("dance4");      // end of stop all animations
        menu = "";                              // set menu to default
        llDialog(agentKey, "\n \n                              main1 Menu\n \n Select your choice", mainButtons, channel);
    }
}
unknownMenuHandler(string message)
{
    llInstantMessage(agentKey, "Unknown menu item - " + message);
    stopListening();
}
default
{
    state_entry()
    {
        init();
    }
    on_rez(integer start_param)
    {
        init();
    }

    touch_start(integer total_number)
    {
        if(listener != 0 && llDetectedKey(0) != agentKey)   // someone else using this?
        {
            llInstantMessage(llDetectedKey(0), agentName + " is using that.");
            return;
        }
        agentKey = llDetectedKey(0);        // remember who is using this
        agentName = llDetectedName(0);
llRequestPermissions(agentKey, PERMISSION_TRIGGER_ANIMATION);
        if(listener == 0)                   // if we are not listening already
        {
            channel = (integer)(llFrand(99999.0) * -1); //yup a different channel at each use
            listener = llListen(channel, agentName, agentKey, "");  // start listening only to the agent on our hidden channel
        } 
        menu = "";                          // set menu to default
        llDialog(agentKey, "Pick which configuration of size's you think will work best for you and your partner", mainButtons, channel);
        llSetTimerEvent(timeout);           // set timeout
    }
    listen(integer channel, string name, key id, string message)
    {
        if(menu == "") mainMenuHandler(message);    // handle results based on menu end-user was viewing
        else if(menu == "main1") main1MenuHandler(message);
        else if(menu == "main2") main2MenuHandler(message);
        else if(menu == "main3") main3MenuHandler(message);
        else if(menu == "main4") main4MenuHandler(message);
        else unknownMenuHandler(message);
    }
    timer()
    {
        llInstantMessage(agentKey, "Your menu has timed out!"); // let agent know that we are not listening
       
        stopListening();
    }
}