Jump to content

Dialog function to handle extra command buttons on first page


Susie Chaffe
 Share

You are about to reply to a thread that has been inactive for 4294 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I needed a dialog menu that has extra command buttons on the first page but not on the rest.
I went searching in the library and the forums, but everthing I found was horribly complex.

I came up with the following function which seems to work ok. It handles static buttons on every page, special buttons on first page and cycles through pages.
I am open to comments and constructive critism to make it better. I don't script all that often these days
Before anyone points out I havn't removed the listen, it was deliberate to aid clarity.

The code below is a complete script, just copy and paste.

// Dialog function to handle extra command buttons on first page of menu
 
// GLOBALS
integer chDialog;
integer iPageIdx;
list lstAlpha = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R"];
 
// USER FUNCTIONS
list order_buttons(list buttons) {
	return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
}
 
dialogUser(key av)
{
	// Buttons that will appear on every page - normally navigation buttons
	list lstStatic = ["<< PREV","MAIN","NEXT >>"];
	integer iSpaces = 12-llGetListLength(lstStatic);
 
	// Extra buttons that will appear only on the first page
	list lstExtraBtn = ["Special 1","Special 2","Special 3"];
	integer iAdjSpaces = llGetListLength(lstExtraBtn);
 
	// Dynamic buttons - read from list modify script to read from inventory
	integer iDynLen = llGetListLength(lstAlpha);
 
	// Calculate menu last page index
	integer iMaxPageIdx = (llFloor((float) (iDynLen + iAdjSpaces) / (float) iSpaces));
 
	// Keep pages within limits
	if (iPageIdx < 0 ) iPageIdx = iMaxPageIdx;
	else if (iPageIdx > iMaxPageIdx) iPageIdx = 0;
 
	// Build the button list
	list lstDialog = [];
	integer idxSlot = iPageIdx*iSpaces;
 
	integer i;
	if((0 == iPageIdx) && ([] != lstExtraBtn)) {
		for(i = idxSlot; (i < idxSlot+iSpaces-iAdjSpaces) && (i <= iDynLen-1 ); i++)
			lstDialog += [llList2String(lstAlpha,i) ];
		lstDialog += lstExtraBtn;
	}
 
	else
		for(i = idxSlot; (i < idxSlot+iSpaces) && (i <= iDynLen-1 + iAdjSpaces); i++)
			lstDialog += [llList2String(lstAlpha,i-iAdjSpaces) ];
 
	lstDialog += lstStatic;
 
	// Finally give the user a dialog using order_buttons function to make it sort properly
	llDialog(av, " \n Choose an Option", order_buttons(lstDialog), chDialog);
}
 
// STATES
 
default
{
	state_entry(){
		chDialog = ( -1 * (integer)("0x" + llGetSubString((string)llGetKey(),-7,-1)) );
		llListen( chDialog, "", NULL_KEY, "" );
	}
 
	touch_start(integer num_detected) {
		dialogUser(llDetectedKey(0));
	}
 
	listen( integer channel, string name, key id, string msg ) {
		key k = id;
		if(msg == "<< PREV") {
			iPageIdx--;
			dialogUser(k);
		}
		else if(msg == "NEXT >>") {
			iPageIdx++;
			dialogUser(k);
		}
		else if(msg == "MAIN") {
			iPageIdx=0;
			dialogUser(k);
		}
		else llOwnerSay("You chose : " + msg);
	}
}
<\lsl>
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4294 days.

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
 Share

×
×
  • Create New...