Difference between revisions of "DialogPlus"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(9 intermediate revisions by 5 users not shown)
Line 7: Line 7:
|p4_type=integer|p4_name=channel|p4_desc
|p4_type=integer|p4_name=channel|p4_desc
|p5_type=integer|p5_name=CurMenu|p5_desc=Parsed menu index.
|p5_type=integer|p5_name=CurMenu|p5_desc=Parsed menu index.
|func_desc=Creates a dialog menu for '''storing more then 12 buttons''', very useful for Inventory items, Scanners, and just huge lists.
|func_desc=Creates a dialog menu for '''storing more than 12 buttons''', very useful for Inventory items, Scanners, and just huge lists.
|func_footnote=''''CurMenu'''' will take place of an integer menuindex.<br />This requires a Listen Event when using DialogPlus to allow the Back and Next button to work.
|func_footnote=''''CurMenu'''' will take place of an integer menuindex.<br />This requires a Listen Event when using DialogPlus to allow the Back and Next button to work.
|spec=<lsl>
|spec=
==For a more flexible multi-page solution, without the owner-only restriction, see [[SimpleDialogMenuSystem]]==
<source lang="lsl2">
//Created by Ugleh Ulrik
//Created by Ugleh Ulrik
//This sort of script should cost, but for you free :)
//This sort of script should cost, but for you free :)
//Edited by Taff Nouvelle to put the buttons in correct order.
list order_buttons(list buttons)
{
    return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) +
        llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
}
integer menuindex;
integer menuindex;
DialogPlus(key avatar, string message, list buttons, integer channel, integer CurMenu)
DialogPlus(key avatar, string message, list buttons, integer channel, integer CurMenu)
{
{
     if (llGetListLength(buttons) >12){
     if (12 < llGetListLength(buttons))
    list lbut = buttons;
    list Nbuttons = [];
    if(CurMenu == -1)
     {
     {
         CurMenu = 0;
         list lbut = buttons;
         menuindex = 0;
        list Nbuttons = [];
        if(CurMenu == -1)
        {
            CurMenu = 0;
            menuindex = 0;
        }
 
         if((Nbuttons = (llList2List(buttons, (CurMenu * 10), ((CurMenu * 10) + 9)) + ["Back", "Next"])) == ["Back", "Next"])
            DialogPlus(avatar, message, lbut, channel, menuindex = 0);
        else
            llDialog(avatar, message,  order_buttons(Nbuttons), channel);
     }
     }
    if((Nbuttons = (llList2List(buttons, (CurMenu * 10), ((CurMenu * 10) + 9)) + ["Back", "Next"])) == ["Back", "Next"])
        DialogPlus(avatar, message, lbut, channel, menuindex = 0);
     else
     else
    {
         llDialog(avatar, message, order_buttons(buttons), channel);
         llDialog(avatar, message, Nbuttons, channel);
    }
}else{
    llDialog(avatar, message, buttons, channel);
}
}
}
</source>
</lsl>
|examples=
|examples=<lsl>
<source lang="lsl2">
//remember to put the Specification section above here
// Created by Ugleh Ulrik
//Created by Ugleh Ulrik
// List2DialogPlus Example
//List2DialogPlus Example
 
integer channel = -900;//Here we set the Dialog Channel
// Here we set the Dialog Channel
integer channel = -900;
 
integer listen_handle;
integer listen_handle;
list The_List = ["Option 1", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6", "Option 7", "Option 8",
 
"Option 9", "Option 10", "Option 11", "Option 12", "Option 13", "Option 14", "Option 15", "Option 16", "Option 17",
// Here we make a huge list for an example
"Option 18", "Option 19", "Option 20"];//Here we make a huge list for an example
list The_List = [
    "Option 1", "Option 2", "Option 3",
    "Option 4", "Option 5", "Option 6",
    "Option 7", "Option 8", "Option 9",
    "Option 10", "Option 11", "Option 12",
    "Option 13", "Option 14", "Option 15",
    "Option 16", "Option 17", "Option 18",
    "Option 19", "Option 20"];
 
default
default
{
{
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
        listen_handle = llListen(channel, "",llGetOwner(),"");//We set a listen for only the owner
        key owner = llGetOwner();
        DialogPlus(llGetOwner(), "Select an Option", The_List, channel, menuindex = 0);//Touch_Start we issue menuindex as 0 inside of the function itself
       
        // We set a listen for only the owner
        // So this script assumes the object will only be touched by the owner
        listen_handle = llListen(channel, "", owner, "");
       
        // Touch_Start we issue menuindex as 0 inside of the function itself
        DialogPlus(owner, "Select an Option", The_List, channel, menuindex = 0);
     }
     }
      
 
    listen(integer chan, string name, key id, string msg){//We need a listen for the dialog itself, but as well as the Back/Next button.
     // We need a listen for the dialog itself, but as well as the Back/Next button.
        if(msg == "Next")
    listen(integer chan, string name, key id, string msg)
    {
        key owner = llGetOwner();
 
        // If they clicked Next it will go to the next dialog window
        if(msg == "Next")
         {
         {
             //If they clicked Next it will go to the next dialog window
             // ++menuindex will turn menuindex plus 1, making it give the next page.
             DialogPlus(llGetOwner(), "Select an Option", The_List, channel, ++menuindex);
             DialogPlus(owner, "Select an Option", The_List, channel, ++menuindex);
            //++menuindex will turn menuindex plus 1, making it give the next page.
         }
         }
        // if they clicked back it will go to the last dialog window.
         else if(msg == "Back")
         else if(msg == "Back")
            DialogPlus(owner, "Select an Option", The_List, channel, --menuindex);
            // --menuindex will turn menuindex minus 1, making it give the previous page.
        // If they choose anything besides Back/Next it will be in this section
        else
         {
         {
             //if they clicked back it will go to the last dialog window.
             // Be Safe
            DialogPlus(llGetOwner(), "Select an Option", The_List, channel, --menuindex);
            llListenRemove(listen_handle);
             //--menuindex will turn menuindex minus 1, making it give the previous page.
             //Example used, change to whatever you wish.
        }else{
             llSay(0, "Your choice was " + msg);
            //If they choose anything besides Back/Next it will be in this section
        }
            llListenRemove(listen_handle); //Be Safe
             llSay(0,"Your choice was "+ msg);//Example used, change to whatever you wish.
    }
     }
     }
}
}
</lsl>
</source>


<lsl>
<source lang="lsl2">
//remember to put the Specification section above here
//Created by Ugleh Ulrik
//Created by Ugleh Ulrik
//Inventory2DialogPlus Example
//Inventory2DialogPlus Example
integer channel = -900;//Here we set the Dialog Channel
 
//Here we set the Dialog Channel
integer channel = -900;
 
integer listen_handle;
integer listen_handle;
list InventoryList;
list InventoryList;
default
default
{
{
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
Line 88: Line 126:
         integer i;
         integer i;
         integer a = llGetInventoryNumber(INVENTORY_ALL);
         integer a = llGetInventoryNumber(INVENTORY_ALL);
         do
         do
         InventoryList += [TrimStringToLength(llGetInventoryName(INVENTORY_ALL, i),23)];
         {
         while (a>++i);
            InventoryList += [TrimStringToLength(llGetInventoryName(INVENTORY_ALL, i),23)];
        }
         while (++i < a);


        listen_handle = llListen(channel, "",llGetOwner(),"");//We set a listen for only the owner
        key owner = llGetOwner();
        DialogPlus(llGetOwner(), "Select an Option", InventoryList, channel, menuindex = 0);//Touch_Start we issue menuindex as 0 inside of the function itself
     
        // We set a listen for only the owner
        // So this script assumes the object will only be touched by the owner
        listen_handle = llListen(channel, "", owner,"");
        // touch_start we issue menuindex as 0 inside of the function itself
        DialogPlus(owner, "Select an Option", InventoryList, channel, menuindex = 0);
     }
     }
      
 
    listen(integer chan, string name, key id, string msg){//We need a listen for the dialog itself, but as well as the Back/Next button.
     // We need a listen for the dialog itself, but as well as the Back/Next button.
        if(msg == "Next")
    listen(integer chan, string name, key id, string msg)
    {
        key owner = llGetOwner();
 
        // If they clicked Next it will go to the next dialog window
        if(msg == "Next")
         {
         {
             //If they clicked Next it will go to the next dialog window
             // ++menuindex will turn menuindex plus 1, making it give the next page.
             DialogPlus(llGetOwner(), "Select an Option", InventoryList, channel, ++menuindex);
             DialogPlus(owner, "Select an Option", InventoryList, channel, ++menuindex);
            //++menuindex will turn menuindex plus 1, making it give the next page.
         }
         }
        //if they clicked back it will go to the last dialog window.
         else if(msg == "Back")
         else if(msg == "Back")
         {
         {
             //if they clicked back it will go to the last dialog window.
             // --menuindex will turn menuindex minus 1, making it give the previous page.
            DialogPlus(llGetOwner(), "Select an Option", InventoryList, channel, --menuindex);
            DialogPlus(owner, "Select an Option", InventoryList, channel, --menuindex);
            //--menuindex will turn menuindex minus 1, making it give the previous page.
         }
         }else{
 
            //If they choose anything besides Back/Next it will be in this section
        // If they choose anything besides Back/Next it will be in this section
             llListenRemove(listen_handle); //Be Safe
        else
             llSay(0,"Your choice was "+ msg);//Example used, change to whatever you wish.
        {
    }
            //Be Safe
             llListenRemove(listen_handle);
            //Example used, change to whatever you wish.
             llSay(0, "Your choice was "+ msg);
        }
     }
     }
}
}
</lsl>
</source>
|helpers
|helpers
|notes
|notes
Line 122: Line 178:
|also_articles
|also_articles
|cat1=Examples
|cat1=Examples
|cat2
|cat2=User-Defined_Functions
|cat3
|cat3
|cat4
|cat4
}}
}}

Latest revision as of 15:14, 22 January 2015

Summary

Function: DialogPlus( key avatar, string message, list buttons, integer channel, integer CurMenu );

Creates a dialog menu for storing more than 12 buttons, very useful for Inventory items, Scanners, and just huge lists.

• key avatar
• string message message to be displayed
• list buttons button labels
• integer channel
• integer CurMenu Parsed menu index.

'CurMenu' will take place of an integer menuindex.
This requires a Listen Event when using DialogPlus to allow the Back and Next button to work.

Specification

For a more flexible multi-page solution, without the owner-only restriction, see SimpleDialogMenuSystem

//Created by Ugleh Ulrik
//This sort of script should cost, but for you free :)
//Edited by Taff Nouvelle to put the buttons in correct order.

list order_buttons(list buttons)
{
    return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) +
        llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
}

integer menuindex;

DialogPlus(key avatar, string message, list buttons, integer channel, integer CurMenu)
{
    if (12 < llGetListLength(buttons))
    {
        list lbut = buttons;
        list Nbuttons = [];
        if(CurMenu == -1)
        {
            CurMenu = 0;
            menuindex = 0;
        }

        if((Nbuttons = (llList2List(buttons, (CurMenu * 10), ((CurMenu * 10) + 9)) + ["Back", "Next"])) == ["Back", "Next"])
            DialogPlus(avatar, message, lbut, channel, menuindex = 0);
        else
            llDialog(avatar, message,  order_buttons(Nbuttons), channel);
    }
    else
        llDialog(avatar, message,  order_buttons(buttons), channel);
}

Examples

// Created by Ugleh Ulrik
// List2DialogPlus Example

// Here we set the Dialog Channel
integer channel = -900;

integer listen_handle;

// Here we make a huge list for an example
list The_List = [
    "Option 1", "Option 2", "Option 3",
    "Option 4", "Option 5", "Option 6",
    "Option 7", "Option 8", "Option 9",
    "Option 10", "Option 11", "Option 12",
    "Option 13", "Option 14", "Option 15",
    "Option 16", "Option 17", "Option 18",
    "Option 19", "Option 20"];

default
{
    touch_start(integer total_number)
    {
        key owner = llGetOwner();
        
        // We set a listen for only the owner
        // So this script assumes the object will only be touched by the owner
        listen_handle = llListen(channel, "", owner, "");
        
        // Touch_Start we issue menuindex as 0 inside of the function itself
        DialogPlus(owner, "Select an Option", The_List, channel, menuindex = 0);
    }

    // We need a listen for the dialog itself, but as well as the Back/Next button.
    listen(integer chan, string name, key id, string msg)
    {
        key owner = llGetOwner();

        // If they clicked Next it will go to the next dialog window
        if(msg == "Next")
        {
            // ++menuindex will turn menuindex plus 1, making it give the next page.
            DialogPlus(owner, "Select an Option", The_List, channel, ++menuindex);
        }

        // if they clicked back it will go to the last dialog window.
        else if(msg == "Back")
            DialogPlus(owner, "Select an Option", The_List, channel, --menuindex);
            // --menuindex will turn menuindex minus 1, making it give the previous page.

        // If they choose anything besides Back/Next it will be in this section
        else
        {
            // Be Safe
            llListenRemove(listen_handle);
            //Example used, change to whatever you wish.
            llSay(0, "Your choice was " + msg);
        }
    }
}
//Created by Ugleh Ulrik
//Inventory2DialogPlus Example

//Here we set the Dialog Channel
integer channel = -900;

integer listen_handle;

list InventoryList;

default
{
    touch_start(integer total_number)
    {
        InventoryList = [];
        integer i;
        integer a = llGetInventoryNumber(INVENTORY_ALL);

        do
        {
            InventoryList += [TrimStringToLength(llGetInventoryName(INVENTORY_ALL, i),23)];
        }
        while (++i < a);

        key owner = llGetOwner(); 
      
        // We set a listen for only the owner
        // So this script assumes the object will only be touched by the owner
        listen_handle = llListen(channel, "", owner,"");
        // touch_start we issue menuindex as 0 inside of the function itself
        DialogPlus(owner, "Select an Option", InventoryList, channel, menuindex = 0);
    }

    // We need a listen for the dialog itself, but as well as the Back/Next button.
    listen(integer chan, string name, key id, string msg)
    {
        key owner = llGetOwner();

        // If they clicked Next it will go to the next dialog window
        if(msg == "Next")
        {
            // ++menuindex will turn menuindex plus 1, making it give the next page.
            DialogPlus(owner, "Select an Option", InventoryList, channel, ++menuindex);
        }

        //if they clicked back it will go to the last dialog window.
        else if(msg == "Back")
        {
            // --menuindex will turn menuindex minus 1, making it give the previous page.
            DialogPlus(owner, "Select an Option", InventoryList, channel, --menuindex);
        }

        // If they choose anything besides Back/Next it will be in this section
        else
        {
            //Be Safe
            llListenRemove(listen_handle);
            //Example used, change to whatever you wish.
            llSay(0, "Your choice was "+ msg);
        }
    }
}