Ackley Bing Posted May 22, 2016 Share Posted May 22, 2016 I made this script which resulted in me having to make a wrap() function for numbers that exceed a maximum. I'm not a mathematician, but I wrote this crazy formula myself. It seems to work, but now that I almost finished with my script, it seems to be giving incorrect results. Does anyone know of a standard math equation to do the same thing? Or how I can fix this formula?// List2DialogButtons() for llDialog use // example: llDialog(id,"",List2DialogButtons(Gdummylist,Gindex),1); // Uses "<<" & ">>" dialog buttons for navigation 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; list List2DialogButtons(list chain, integer i) { list buttons; integer j=llGetListLength(chain); if (j>12) buttons= ["<<"] +llList2List(chain,wrap(i+9,j),wrap(i+9,j)) +[">>"] +llList2List(chain,wrap(i+6,j),wrap(i+8,j)) +llList2List(chain,wrap(i+3,j),wrap(i+5,j)) +llList2List(chain,wrap(i,j),wrap(i+2,j)); else { integer k; do buttons+=llList2List(chain,k,k); while(++k<j); } return buttons; } integer wrap(integer x,integer max){return (((x<0)*(x+max))+((x>=0&&x<max)*x)+((x>=max)*(x-max)));} 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 total=llGetListLength(Gdummylist); Gindex=Gindex+((message==">>")*9)-((message=="<<")*9); if(Gindex>=total)Gindex=Gindex-total; else if(Gindex<0)Gindex=total-Gindex-2; llDialog(llGetOwner()," ",List2DialogButtons(Gdummylist,Gindex),1); } else { integer find_index=llListFindList(Gdummylist,[message]); if(~find_index) { //Gindex=find_index; //Action(Gindex); } } } } Link to comment Share on other sites More sharing options...
Charlotte Holmeforth Posted May 23, 2016 Share Posted May 23, 2016 Is it to get buttons into the right order? Once I have the buttons I want, I use this: lDialogButtons = llList2List(lDialogButtons,-3,-1) + llList2List(lDialogButtons,-6,-4) + llList2List(lDialogButtons,-9,-7) + llList2List(lDialogButtons,-12,-10); it makes a new list by re-ordering the buttons in groups of three, starting from the end of the list, so that the last three buttons end up at the top and the first three at the bottom. Usually I put page navigation buttons on the last row - << OK >> - then the rest of the buttons line up. Link to comment Share on other sites More sharing options...
Ackley Bing Posted May 23, 2016 Author Share Posted May 23, 2016 Yes. Also I made the script seamlessly connect the end with the beginning, with no gapsFor example: x,y,z,a,b,c,d,e... instead of just x,y,z. Ordering is fine: [a] [b] [c][d] [e] [f][g] [h] [i][<] [j] [>][j] [k] [l][m] [n] [o][p] [q] [r][<] [s] [>] Up until the end,where it does this: [s] [t] [u][v] [w] [x][a] [y] [z][<] [b] [>] Notice the buttons, a,y,z. The problem is in the wrap(). I will fix it with enough trial and error... I am no mathematician. I was hoping there might be some standard math equation to do this instead of my crazy formula. integer wrap(integer x,integer max){return (((x<0)*(x+max))+((x>=0&&x<max)*x)+((x>=max)*(x-max)));} Link to comment Share on other sites More sharing options...
Charlotte Holmeforth Posted May 23, 2016 Share Posted May 23, 2016 I would do the layout like this, so 9 buttons per page, and the last row is all navigation. There's a spacer button after z, to keep the rest of the buttons aligned. If you wanted to wrap to the beginning you could go back to a on the next page. [a] [c] [d] [e] [f] [g] [h] [|] [ok] [>] [j] [k] [l] [m] [n] [o] [p] [q] [r] [<] [ok] [>] [t] [v] [w] [x] [y] [z] [-] [<] [ok] [|] Link to comment Share on other sites More sharing options...
Nova Convair Posted May 23, 2016 Share Posted May 23, 2016 For this kind of overflow the modulo operation % becomes handy. 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),">>"] +llList2List(chain,(i+6)%j,(i+8)%j) +llList2List(chain,(i+3)%j,(i+5)%j) +llList2List(chain,i,(i+2)%j); else { integer k; do buttons+=llList2List(chain,k,k); while(++k<j); } return buttons;}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 { llOwnerSay(message); Gindex=0; } }} No need for crazy formulas. 3 Link to comment Share on other sites More sharing options...
wherorangi Posted May 23, 2016 Share Posted May 23, 2016 Nova's use of modulus is the way to go another issue OP has is when a 3 button bracket spans the bounds. In this case [max-1,0,1] and [max-2,max-1,0]. To catch this a way to mod Nova's code is: 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); } ...list List2DialogButtons(list chain, integer i) { ... 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 ...}...listen(integer channel, string name, key id, string message){ ... if (message == "<<") { Gindex -= 10; if (Gindex < 0) Gindex += j; } else if (message == ">>") Gindex = (Gindex + 10) % j; ...} 1 Link to comment Share on other sites More sharing options...
Nova Convair Posted May 23, 2016 Share Posted May 23, 2016 wherorangi wrote: Nova's use of modulus is the way to go another issue OP has is when a 3 button bracket spans the bounds. In this case [max-1,0,1] and [max-2,max-1,0]. To catch this a way to mod Nova's code is: Nope. llList2List does the wrap. No extra code needed. llList2List(chain,25,1) will return the list elements: 25,0,1 The extra wrap function is obsolete. Link to comment Share on other sites More sharing options...
wherorangi Posted May 23, 2016 Share Posted May 23, 2016 try stepping back Link to comment Share on other sites More sharing options...
Ackley Bing Posted May 24, 2016 Author Share Posted May 24, 2016 Thanks Nova This a lot less crazy yet i'm still getting button ordering like [a] [y] [z]. Link to comment Share on other sites More sharing options...
Ackley Bing Posted May 24, 2016 Author Share Posted May 24, 2016 Your wrap does the trick. Thanks to everyone here is what I finally came up with. 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... } } }} Link to comment Share on other sites More sharing options...
Ackley Bing Posted May 24, 2016 Author Share Posted May 24, 2016 The Formula was 100% correct!! But not needed because SL has % !!! :catlol: Link to comment Share on other sites More sharing options...
wherorangi Posted May 24, 2016 Share Posted May 24, 2016 Ackley Bing wrote: i'm still getting button ordering like [a] [y] [z]. yes. That was my point we do have to account for this when ordering brackets/sets of 3, when 10 is not a factor of max (24) certainly yes tho, modulus like Nova says is the way to do this. [is the base building block] another way to do the accounting is to swap the list parameter indices (X with Y) when required. Doing this tho requires a test also to keep the main body as inline code (as wrote originally) then the test has to be done in a external function (typically minmax), and if we are going to conform to this inline coding style then it makes sense for the test function to return the set as well eta: base Link to comment Share on other sites More sharing options...
wherorangi Posted May 24, 2016 Share Posted May 24, 2016 Ackley Bing wrote: BTW, your listen event gave me an error on compile :smileywink: j is not declared in the event. correct. Is just p-code that shows the edits. The actual editing of your codes is for you to do (: Link to comment Share on other sites More sharing options...
Ackley Bing Posted May 24, 2016 Author Share Posted May 24, 2016 Thanks again I gave both of you credit in my final posting on the wiki https://wiki.secondlife.com/wiki/User:Ackley_Bing/List2DialogButtons 2 Link to comment Share on other sites More sharing options...
wherorangi Posted May 24, 2016 Share Posted May 24, 2016 is a pretty cool idea this. A circular button menu dialog i like it Link to comment Share on other sites More sharing options...
Rolig Loon Posted May 24, 2016 Share Posted May 24, 2016 Lovely work. :smileyvery-happy: I'll add that to my collection of menu managers. Here are a couple of others that take different approaches to the same problem. https://community.secondlife.com/t5/LSL-Library/A-Simple-MultiPage-Dialog-Menu-System/m-p/2126747 https://community.secondlife.com/t5/LSL-Library/Dynamic-Multi-page-Dialog-AKA-Pagination/m-p/708119 1 Link to comment Share on other sites More sharing options...
Ackley Bing Posted May 25, 2016 Author Share Posted May 25, 2016 Yes. Circular is what i'm looking for because my of Next Idea, which, btw, is sacret, for now. There is still a bug in this here. When you click thru... it's producing [a][z] and [a][y][z]. Link to comment Share on other sites More sharing options...
Ackley Bing Posted May 25, 2016 Author Share Posted May 25, 2016 Aw Thank You Rolig Hey, with enough invention we'll be getting vehicles with 4 different wheels! Link to comment Share on other sites More sharing options...
wherorangi Posted May 25, 2016 Share Posted May 25, 2016 Ackley Bing wrote: Yes. Circular is what i'm looking for because my of Next Idea, which, btw, is sacret, for now. There is still a bug in this here. When you click thru... it's producing [a][z] and [a][y][z]. is that when you go backwards ? eta: ps. I let you off ok (: look again at the edits pcode and work thru why the last edit treats going backwards different to going forwards ? Link to comment Share on other sites More sharing options...
Recommended Posts
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