Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Unlimited Pages Drop-down Menu (Instant Create ← PREV / NEXT →)

Klug Kuhn
Registered User
Join date: 7 Sep 2007
Posts: 126
09-23-2009 18:13
I'm pretty sure there're some menu snippets already. This one i was written not long ago and found it can be very useful in many situations regarding future menu creation. So i think it would worth for sharing, hope you'll like it. :)

The idea is simple. You have a data list which to be used for the drop-down menu. This list can be any pre-defined list, or any list that generated thru a running script. A person touches the prim and the according proper menu will show up with the ← PREV / NEXT → button for different pages. The snippet will find out how many total pages as well as to make the ← PREV / NEXT → button automatically. You only need to feed in the list, and don't have to worry about the list length as long as the script memory can handle.

The example was having a pre-defined list with 30 data, the menu buttons will be shown as numbers to represent the data.
Klug Kuhn
Registered User
Join date: 7 Sep 2007
Posts: 126
09-23-2009 18:15
CODE

list data_list = [
"Button 1 data",
"Button 2 data",
"Button 3 data",
"Button 4 data",
"Button 5 data",
"Button 6 data",
"Button 7 data",
"Button 8 data",
"Button 9 data",
"Button 10 data",
"Button 11 data",
"Button 12 data",
"Button 13 data",
"Button 14 data",
"Button 15 data",
"Button 16 data",
"Button 17 data",
"Button 18 data",
"Button 19 data",
"Button 20 data",
"Button 21 data",
"Button 22 data",
"Button 23 data",
"Button 24 data",
"Button 25 data",
"Button 26 data",
"Button 27 data",
"Button 28 data",
"Button 29 data",
"Button 30 data"
];
//===============================
integer total_data = 0;
key toucher = NULL_KEY;
integer menu_chan = -1;
integer listen_num = -1;
integer menu_page = 1;
integer total_menu_page = 1;
integer i = 0;
string menu_msg = "";
list menu_button = [];
//===============================
create_menu(integer current_page)
{
llListenRemove(listen_num);
menu_chan = 0 - (integer)llFrand(2147483647);
listen_num = llListen(menu_chan,"", toucher,"");
menu_button = [];
menu_msg = "";

if (total_menu_page == 1) // only 1 total menu page
{
for (i = 0; i <= 11; i++)
{
menu_msg += (string)(i + 1)+" ⇒ "+llList2String(data_list,i)+"\n";
menu_button += [(string)(i + 1)];
}
}
else if (current_page == 1) // more than 1 total menu page, and the current page is 1
{
for (i = 0; i <= 10; i++)
{
menu_msg += (string)(i + 1)+" ⇒ "+llList2String(data_list,i)+"\n";
menu_button += [(string)(i + 1)];
}
menu_button = llListInsertList(menu_button,["NEXT →"],2); // add a next page button
}
else if (current_page == total_menu_page) // more than 1 total menu page, and now is the last page
{
for (i = (total_menu_page - 1) * 10; i <= (total_data - 1); i++)
{
menu_msg += (string)(i + 1)+" ⇒ "+llList2String(data_list,i)+"\n";
menu_button += [(string)(i + 1)];
}
menu_button = llListInsertList(menu_button,["← PREV"],0); // add a previous page button
}
else // more than 1 total menu page, it is now in the middle page
{
for (i = (current_page - 1) * 10; i <= (current_page - 1) * 10 + 9; i++)
{
menu_msg += (string)(i + 1)+" ⇒ "+llList2String(data_list,i)+"\n";
menu_button += [(string)(i + 1)];
}
menu_button = llListInsertList(menu_button,["← PREV"],0); // add a previous page button
menu_button = llListInsertList(menu_button,["NEXT →"],2); // add a next page button
}

llDialog(toucher, "Select option (page "+(string)current_page+"/"+(string)total_menu_page+"):\n"+menu_msg, menu_button, menu_chan);
llSetTimerEvent(60.0);
}
//===============================
integer get_total_page(integer total_data)
{
integer output = 1;
while ((float)output * 10.0 + 2.0 < total_data)
{
output += 1;
}
return output;
}
//===============================
Klug Kuhn
Registered User
Join date: 7 Sep 2007
Posts: 126
09-23-2009 18:16
CODE

default
{
state_entry()
{
total_data = llGetListLength(data_list);
total_menu_page = get_total_page(total_data);
}
touch_start(integer int)
{
if (data_list != [])
{
toucher = llDetectedKey(0);
menu_page = 1;
create_menu(menu_page);
}
}
listen(integer channel, string name, key id, string message)
{
if (message == "NEXT →")
{
menu_page += 1;
create_menu(menu_page);
}
else if (message == "← PREV")
{
menu_page -= 1;
create_menu(menu_page);
}
else // menu button selected
{
integer temp_slot = (integer)message - 1; // minus 1 since menu button starts from 1, not 0
llOwnerSay(" selected button = "+message+", its list data = "+llList2String(data_list,temp_slot));
}
}
timer()
{
llListenRemove(listen_num);
llSetTimerEvent(0.0);
}
}