Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Library: Dynamic Multi-Paged llDialog w/ Sequence Fixing (example included)

Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
09-24-2007 23:53
EDIT: Updated as of 2009-1-19
If the title means gibberish to you, here's what it does.
A: Dynamically returns a correct sized list to llDialog (12 or less items)

B: puts your llDialog buttons in english order(left to right Then TOP TO BOTTOM) instead of the default order(left to right, bottom to top)

C: automatically inserts a Back and Forward button on each page, with the page number encoded

D: remenu compatible (auto pop-the same page on item selection, if you want)

E: allows handling multiple users on the same chat channel (because all page changes are encoded into the fwd/bck buttons)

CODE

/*//-- Note:
This function replaces the list in llDialog.
Expected input is 1 (default) or greater
input outside the possible page range
will redirect to valid pages but the
other page buttons may be absent.

Requires the button text(s) to be
in a gloabal list named gLstMnu.

single button text length > 24
causes errors in llDialog.
Make sure you sanitize
button text lengths
BEFOREHAND!
//*/
list uDlgBtnLst( integer vIntPag ){
integer vIdxBeg = 10 * ~-vIntPag; //-- "~-x" == "x - 1"
integer vIdxMax = -~(~([] != gLstMnu) / 10); //-- integer math to get last valid page
list vLstRtn =
llListInsertList(
llList2List( gLstMnu, vIdxBeg, vIdxBeg + 9 ), //-- grab 10 dialog buttons
(list)(" <<---(" + (string)(vIntPag + (-(vIntPag > 1) | vIdxMax - vIntPag)) + ";)";), //-- back button
-1 ) + //-- inserts back button before last item
(list)(" (" + (string)(-~((vIntPag < vIdxMax) * vIntPag)) + ";)--->>";); //-- tack on the fwd button

return //-- fun trick to fix the order for L2R T2B
llList2List( vLstRtn, -3, -1 ) + llList2List( vLstRtn, -6, -4 ) +
llList2List( vLstRtn, -9, -7 ) + llList2List( vLstRtn, -12, -10 );
}
/*//-- Anti-License Text --//*/
/*// Contributed Freely to the Public Domain without limitation. //*/
/*// 2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ] //*/
/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/
/*//-- --//*/

Addendum:

===initial call example:
CODE

llDialog( Target_avatar_key, text_for_dialog_header, uDlgBtnLst( 1 ), chat_channel_to_use );


===to detect the next page button use the following format
CODE

listen( integer vIntChn, string vStrNom, key vKeySpk, string vStrMsg ){
if (!llSubStringIndex( vStrMsg, " " )){ //-- detects 2 leading spaces
llDialog( vKeySpk,
"dialog text",
//-- next line parse the next page request
uDlgBtnLst( (integer)llGetSubString( vStrMsg, -~llSubStringIndex( vStrMsg, ";(" ), -1 ) ),
vIntChn );
}else{
//-- button was not a page change button, act on vStrMsg as needed
}
}


===you can get the remenu page number with this formula (assuming a page change was not called)
CODE

integer vIntReMenuPage = -~(llListFindList( gLstMnu, (list)vStrMsg ) / 10);


===and a VERY simple example, that demonstrates it in use.
CODE

//--// Completely pointless example

integer gBooLIO = TRUE; //-- Listen is off
integer gIntChn = -42; //-- listen channel
float gFltTmt = 45.0; //-- seconds to wait since last dialog to clear listen
string gStrDlg = "This Dialog is Pointless, pick something anyway =P";

list gLstMnu = //-- build this anyway you want....
["00","01","02","03","04","05","06","07","08","09",
"10","11","12","13","14","15","16","17","18","19",
"20","21","22","23","24","25","26","27","28","29",
"30","31","32","33","34","35","36","37","38","39"
];

list uDlgBtnLst( integer vIntPag ){
integer vIdxBeg = 10 * ~-vIntPag; //-- "~-x" == "x - 1"
integer vIdxMax = -~(~([] != gLstMnu) / 10); //-- integer math to get last valid page
list vLstRtn =
llListInsertList(
llList2List( gLstMnu, vIdxBeg, vIdxBeg + 9 ), //-- grab 10 dialog buttons
(list)(" <<---(" + (string)(vIntPag + (-(vIntPag > 1) | vIdxMax - vIntPag)) + ";)";), //-- back button
-1 ) + //-- inserts back button before last item
(list)(" (" + (string)(-~((vIntPag < vIdxMax) * vIntPag)) + ";)--->>";); //-- tack on the fwd button

return //-- fun trick to fix the order for L2R T2B
llList2List( vLstRtn, -3, -1 ) + llList2List( vLstRtn, -6, -4 ) +
llList2List( vLstRtn, -9, -7 ) + llList2List( vLstRtn, -12, -10 );
}

default{
touch_end( integer vIntTch ){
if (gBooLIO){
llListen( gIntChn , "", "", "" );
gBooLIO = !gBooLIO;
}
llSetTimerEvent( gFltTmt );
do{
llDialog( llDetectedKey( --vIntTch ),
gStrDlg,
uDlgBtnLst( 1 ),
gIntChn );
}while (vIntTch);
}

listen( integer vIntChn, string vStrNom, key vKeySpk, string vStrMsg ){
if (!llSubStringIndex( vStrMsg, " " )){ //-- detects 2 leading spaces
llSetTimerEvent( gFltTmt );
llDialog( vKeySpk,
gStrDlg,
uDlgBtnLst( (integer)llGetSubString( vStrMsg, -~llSubStringIndex( vStrMsg, ";(" ), -1 ) ),
vIntChn );
}else{
integer vIdxFnd = llListFindList( gLstMnu, (list)vStrMsg );
if (~vIdxFnd){
llSetTimerEvent( gFltTmt );
llSay( 0, vStrNom + " picked " + vStrMsg );
//-- remenu on the next line
llDialog( vKeySpk, gStrDlg, uDlgBtnLst( -~(vIdxFnd / 10) ), vIntChn );
}
}
}

timer(){
gBooLIO = !gBooLIO;
llSetTimerEvent( 0.0 );
state sListenKiller;
}
}

state sListenKiller{
state_entry(){
//-- just here to turn off all active listen and go back
state default;
}
}
Chrysala Desideri
Scarlet Scriptrix
Join date: 4 Mar 2007
Posts: 65
09-30-2007 06:12
Wow i have't tried it yet but this sounds like the holy grail of llDialog!

Thanks!
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
09-30-2007 09:28
it MAY recieve a slight rework... to allow it to diplay the last page first (in the case of archived class notes this is good) and or to completely reverse the order (in the same case, the oldest note would be first on the list...

I've done both, but they were quickie hard coded... if someone is bored, they're welcome to post the addition (I was thinking two more iput fields, button order, page order)... just trying to avoid taking the WHOLE list and rebuilding it in that order for reasons of script overhead

(guess LL took Bill Gates to heart when he said 64k should be enough for anyone)
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
10-01-2007 08:31
yay!

thanks, void, very cool. :)


um... but what about a 'back' button besides a 'more' button? ;)




and bill gates? the 64k thing was back in the days of the commie 64. dont recall him being around then. plus, ainnit 16k per script? ;)
chechel Choche
Registered User
Join date: 1 May 2007
Posts: 5
01-25-2008 03:03
...First Script:

Error: (28, 0) : ERROR : Syntac error

...second Script (Notecardgiver):

script compiling OK

but when i put a note card inside and klick ok
(the note cart not appear in the menu, only the OK Button)
Object: Unable to give inventory: No item named 'OK'

what is wrong here ?? ;)


greetings CC
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-26-2008 10:12
lost some formating on the original example
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-18-2010 15:30
*Bumpage for the redesign of this function, see first post for details!*
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-18-2010 23:32
From: Void Singer

E: allows handling multiple users on the same chat channel (because all page changes are encoded into the fwd/bck buttons)

was that an accident? awesome accident if it was, but can't think of anything it would be useful for.

eta: well maybe a dialoged menu, like dance machines, or drink machines, but it could be funny if multiple users try to change prim properties at the same time, like color/texture menus
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-19-2010 07:53
From: Ruthven Willenov
was that an accident? awesome accident if it was, but can't think of anything it would be useful for.

eta: well maybe a dialoged menu, like dance machines, or drink machines, but it could be funny if multiple users try to change prim properties at the same time, like color/texture menus

actually it was by design, since I ran into a problem of having to track what page a particular user was on with simple back and fwd buttons on a item giver... why track when you can get the info handed to you each time =) with encoding them in the button, you don't have to track any of that. you don't HAVE to use that feature, but it's a nice option to cut down on excessive listens. dance machines, pose setters, anything you need more than twelve items for, and individual treatment of the option.

I went with symbol/number buttons for language flexibility, but it's not required, you could go any other route you want including hiding the numerical part off screen, by padding with a character like"." (spaces are collapsed/trimmed).

it should be adaptable to multilevel menus too, by feeding it ranges for the start and end positions of the sub menu (requires tweaking) so it could be good for us in things like MLP or anything else that uses multilevel menus but has categories that are beyond 12 items.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -