Mon, 10/04/2010 - 13:54 by xantarius.cain
Type:
LSL Script
A very basic dialog menu that is meant to be used as a learning tool. With this, and a little creativity, more complex and feature-rich menu systems can be built. Right now, the menu simply has two options and clicking either will result in something being said to you.
Fun Learning Exercise:
Combine this simple menu script with notecard and landmark distributor scripts and allow avatars to touch a prim and choose to receive either a notecard or a landmark.
Source Code:
list MENU_MAIN = ["Hello", "Goodbye"]; // up to 12 items in list
integer menu_handler;
integer menu_channel;
menu(key user,string title,list buttons)
{
llListenRemove(menu_handler);
menu_channel = (integer)(llFrand(99999.0) * -1);
menu_handler = llListen(menu_channel,"","","");
llDialog(user,title,buttons,menu_channel);
llSetTimerEvent(30.0); // how long to wait for user to press a button
}
default
{
state_entry()
{
// nothing
}
touch_start(integer total_number)
{
menu(llDetectedKey(0), "\nText for Menu.", MENU_MAIN);
}
listen(integer channel,string name,key id,string message)
{
if (channel == menu_channel)
{
llListenRemove(menu_handler); // close listen
llSetTimerEvent(0); // stop timeout timer
if (message == "Hello")
{
llSay(0, "Hello to you!");
}
else if (message == "Goodbye")
{
llSay(0, "Have a nice day!");
}
// else if (message == "Button")
//{
// do something
//}
}
}
timer() // VERY IMPORTANT menu timeout
{
llListenRemove(menu_handler); // close listen
llSetTimerEvent(0); // stop timeout timer
}
}
integer menu_handler;
integer menu_channel;
menu(key user,string title,list buttons)
{
llListenRemove(menu_handler);
menu_channel = (integer)(llFrand(99999.0) * -1);
menu_handler = llListen(menu_channel,"","","");
llDialog(user,title,buttons,menu_channel);
llSetTimerEvent(30.0); // how long to wait for user to press a button
}
default
{
state_entry()
{
// nothing
}
touch_start(integer total_number)
{
menu(llDetectedKey(0), "\nText for Menu.", MENU_MAIN);
}
listen(integer channel,string name,key id,string message)
{
if (channel == menu_channel)
{
llListenRemove(menu_handler); // close listen
llSetTimerEvent(0); // stop timeout timer
if (message == "Hello")
{
llSay(0, "Hello to you!");
}
else if (message == "Goodbye")
{
llSay(0, "Have a nice day!");
}
// else if (message == "Button")
//{
// do something
//}
}
}
timer() // VERY IMPORTANT menu timeout
{
llListenRemove(menu_handler); // close listen
llSetTimerEvent(0); // stop timeout timer
}
}









