User:Trinity Coulter/Example Script for Menus ( llDialog )
Jump to navigation
Jump to search
Just a simple example of more than 1 layer of menus in a script. Needs lots of improvement, but its intended to just help give an example for a person new to scripting.
<lsl> list main_menu = ["Blue", "Red"]; list blue_menu = ["Blue Stuff 1", "Blue Stuff 2", "Back"]; list red_menu = ["Red Stuff 1", "Red Stuff 2", "Back"]; integer submenu = FALSE; integer listen_channel = 1;
default {
state_entry()
{
llListen(listen_channel,"",llGetOwner(),"");
llSay(0, "Hello, Avatar!");
}
touch_start(integer total_number)
{
llSay(0, "Touched.");
llDialog(llDetectedKey(0),"Try a selection...", main_menu, listen_channel);
}
listen(integer channel, string name, key id, string message)
{
if (submenu == FALSE)
{
// Use a main menu verification
if (message == "Blue")
{
llSay(0,"Thanks for picking " + message);
llDialog(id,message + " Dialog", blue_menu, listen_channel);
}
if (message == "Red")
{
llSay(0,"Thanks for picking " + message);
llDialog(id,message + " Dialog", red_menu, listen_channel);
}
submenu = TRUE;
llSetTimerEvent(20.0);
}
else
{
// Use a sub menu verification
llSetTimerEvent(20.0);
if (message == "Back")
{
llDialog(id,message + " Dialog", main_menu, listen_channel);
submenu = FALSE;
}
else
{
llSay(0,"You picked " + message);
//might want to verify which sub-menu was being used to redisplay here, etc
submenu = FALSE;
}
}
}
timer()
{
llSetTimerEvent(0.0);
llSay(0,"You waited too long to pick, resetting menu.");
submenu = FALSE;
}
} </lsl>