Difference between revisions of "User:Ackley Bing/List2DialogButtons"

From Second Life Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
// example: llDialog(id,"",List2DialogButtons(Gdummylist,Gindex),1);
// example: llDialog(id,"",List2DialogButtons(Gdummylist,Gindex),1);
// Uses "<<" & ">>" dialog buttons for navigation
// Uses "<<" & ">>" dialog buttons for navigation
// Thanks to NovaConvair and Wherorangi for help with math equations.
list Gdummylist=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
list Gdummylist=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
//list Gdummylist=["1","2","3","4","5","6","7","8","9","10","11","12"];
integer Gindex;
integer Gindex;
list List2DialogButtons(list chain, integer i)
list List2DialogButtons(list chain, integer i)
Line 11: Line 11:
     integer j=llGetListLength(chain);
     integer j=llGetListLength(chain);
     if (j>12)
     if (j>12)
         buttons=
         buttons =
        ["<<"]
            ["<<",llList2String(chain,(i+9)%j),">>"]
        +llList2List(chain,wrap(i+9,j),wrap(i+9,j))
            + wrap(chain,(i+6)%j,(i+8)%j)
        +[">>"]
            + wrap(chain,(i+3)%j,(i+5)%j)
        +llList2List(chain,wrap(i+6,j),wrap(i+8,j))
            + wrap(chain,i,(i+2)%j);
        +llList2List(chain,wrap(i+3,j),wrap(i+5,j))
        +llList2List(chain,wrap(i,j),wrap(i+2,j));
     else
     else
     {
     {
Line 26: Line 24:
     return buttons;
     return buttons;
}
}
integer wrap(integer x,integer max){return (((x<0)*(x+max))+((x>=0&&x<max)*x)+((x>=max)*(x-max)));}
list wrap(list c, integer x, integer y)
{
    if(x<=y) return llList2List(c, x, y);
    return llList2List(c,x,-1)+llList2List(c,0,y);
}
default
default
{
{
Line 42: Line 44:
         if(message=="<<"|message==">>")
         if(message=="<<"|message==">>")
         {
         {
             integer total=llGetListLength(Gdummylist);
             integer j=llGetListLength(Gdummylist);
             Gindex=Gindex+((message==">>")*9)-((message=="<<")*9);
             if (message=="<<") Gindex=(Gindex-10)%j;
            if(Gindex>=total)Gindex=Gindex-total;
             else if (message==">>") Gindex=(Gindex+10)%j;
             else if(Gindex<0)Gindex=total-Gindex-2;
             llDialog(llGetOwner()," ",List2DialogButtons(Gdummylist,Gindex),1);
             llDialog(llGetOwner()," ",List2DialogButtons(Gdummylist,Gindex),1);
         }
         }
Line 53: Line 54:
             if(~find_index)
             if(~find_index)
             {
             {
                 // action
                llOwnerSay(message);
                 //actions...
             }
             }
         }
         }

Latest revision as of 21:34, 23 May 2016

// List2DialogButtons() for llDialog use
// example: llDialog(id,"",List2DialogButtons(Gdummylist,Gindex),1);
// Uses "<<" & ">>" dialog buttons for navigation
// Thanks to NovaConvair and Wherorangi for help with math equations.
list Gdummylist=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
integer Gindex;
list List2DialogButtons(list chain, integer i)
{
    list buttons;
    integer j=llGetListLength(chain);
    if (j>12)
        buttons =
            ["<<",llList2String(chain,(i+9)%j),">>"]
            + wrap(chain,(i+6)%j,(i+8)%j)
            + wrap(chain,(i+3)%j,(i+5)%j)
            + wrap(chain,i,(i+2)%j);
    else
    {
        integer k;
        do buttons+=llList2List(chain,k,k);
        while(++k<j);
    }
    return buttons;
}
list wrap(list c, integer x, integer y)
{
    if(x<=y) return llList2List(c, x, y);
    return llList2List(c,x,-1)+llList2List(c,0,y);
}
default
{
    state_entry()
    {
        llListen(1,"",llGetOwner(),"");
    }
    touch_start(integer index)
    {
        Gindex=0;
        llDialog(llGetOwner()," ",List2DialogButtons(Gdummylist,Gindex),1);
    }
    listen(integer channel, string name, key id, string message)
    {
        if(message=="<<"|message==">>")
        {
            integer j=llGetListLength(Gdummylist);
            if (message=="<<") Gindex=(Gindex-10)%j;
            else if (message==">>") Gindex=(Gindex+10)%j;
            llDialog(llGetOwner()," ",List2DialogButtons(Gdummylist,Gindex),1);
        }
        else
        {
            integer find_index=llListFindList(Gdummylist,[message]);
            if(~find_index)
            {
                llOwnerSay(message);
                //actions...
            }
        }
    }
}