Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Menu selecting script – Simple script help

Dragon Muir
Registered User
Join date: 25 Jun 2005
Posts: 60
11-24-2007 13:18
Second Life residents were very helpful when I asked for a simple script example from previous posts. If anyone would provide a simple example for this post I would appreciate it.

1) Anyone can touch the object to activate the script

2) A menu appears with two buttons “A” and “B”

3) Click one of those and it takes you to a submenu each having a menu for “A” of “1”, “2”, “3” and “B” of “I”, “II”, “III”

4) Once one of the last six buttons menu buttons are pushed it will do an “If selected ==” one of the menu buttons it will say, “You selected II.” Or another example, “You selected 3.”

The simplest commands will be the easiest to quickly grasp the concept. This will make it easy to study and understand. Also this basic script will make it easy to apply it to lot of different uses.

If you do not make the script exactly as I suggest, it is alright, because no doubt someone might have a better example that accomplishes the same general goal, which is using menus to cause an event based on the selection.

If you do reply with a basic script example, I hope you do not mind if I send you an instant massage in second life thanking you. ^.=.^
Abba Thiebaud
PerPetUal NoOb
Join date: 20 Aug 2006
Posts: 563
11-24-2007 13:36
Sounds like you're looking for a start like this: /54/b6/46156/1.html

If you want something specifically written for you, please see this forum:/147/1.html

A
_____________________
http://www.ponystars.com/abbathiebaud Pony Up.
Laurence Corleone
Registered User
Join date: 12 Oct 2006
Posts: 126
11-24-2007 13:58
This should get you started. Put whatever you want to do where it says //Do something here.

CODE

// Channel to listen for menu commands
integer MENU_CHANNEL = 97346585;

// Menu prompt and buttons
string MENU_PROMPT = "What do you want to do?";
list MENU_BUTTONS1 = ["A", "B"];

// Sub Menus
list MENU_BUTTONS2 = ["1", "2", "3"];
list MENU_BUTTONS3 = ["I", "II", "III"];

integer TIMEOUT_SECS = 20;
integer hMenu = -1;
showMenu(key id)
{
hMenu = llListen(MENU_CHANNEL, "", id, "");
llDialog(id, MENU_PROMPT, MENU_BUTTONS1, MENU_CHANNEL);
llSetTimerEvent(TIMEOUT_SECS);
}
stopMenuListen()
{
llSetTimerEvent(0);
if (hMenu != -1)
{
llListenRemove(hMenu);
hMenu = -1;
}
}
default
{
touch_start(integer num_detected)
{
integer i;
for (i = 0; i < num_detected; i++)
{
showMenu(llDetectedKey(i));
}
}
listen(integer channel, string name, key id, string msg)
{
if (channel == MENU_CHANNEL)
{
stopMenuListen();

if (msg == "A")
{
hMenu = llListen(MENU_CHANNEL, "", id, "");
llDialog(id, MENU_PROMPT, MENU_BUTTONS2, MENU_CHANNEL);
llSetTimerEvent(TIMEOUT_SECS);
llOwnerSay("You selected A");
}
if (msg == "B")
{
hMenu = llListen(MENU_CHANNEL, "", id, "");
llDialog(id, MENU_PROMPT, MENU_BUTTONS3, MENU_CHANNEL);
llSetTimerEvent(TIMEOUT_SECS);
llOwnerSay("You selected B");
}
if (msg == "1")
{
//Do something here
llOwnerSay("You selected 1");
}
if (msg == "2")
{
//Do something here
llOwnerSay("You selected 2");
}
if (msg == "3")
{
//Do something here
llOwnerSay("You selected 3");
}
if (msg == "I")
{
//Do something here
llOwnerSay("You selected I");
}
if (msg == "II")
{
//Do something here
llOwnerSay("You selected II");
}
if (msg == "III")
{
//Do something here
llOwnerSay("You selected III");
}
}
}
timer()
{
stopMenuListen();
}
on_rez(integer start_param)
{
llResetScript();
}
}
_____________________
There are no stupid questions, just stupid people.
Jadon Christensen
Registered User
Join date: 24 Dec 2005
Posts: 32
12-12-2007 11:04
CODE

//string owner;
//owner = llGetOwner();

// Channel to listen for menu commands
integer MENU_CHANNEL = 9420133;

// Menu prompt and buttons
string MENU_PROMPT = "What do you want to do?";
list MENU_BUTTONS1 = ["Play Nice", "Naughty"];

// Sub Menus
list MENU_BUTTONS2 = ["Pull", "Bite", "Swat"];
list MENU_BUTTONS3 = ["Kiss", "Massage", "Rub"];

integer TIMEOUT_SECS = 20;
integer hMenu = -1;
showMenu(key id)
{
hMenu = llListen(MENU_CHANNEL, "", id, "");
llDialog(id, MENU_PROMPT, MENU_BUTTONS1, MENU_CHANNEL);
llSetTimerEvent(TIMEOUT_SECS);
}
stopMenuListen()
{
llSetTimerEvent(0);
if (hMenu != -1)
{
llListenRemove(hMenu);
hMenu = -1;
}
}
default
{
touch_start(integer num_detected)
{
integer i;
for (i = 0; i < num_detected; i++)
{
showMenu(llDetectedKey(i));
}
}
listen(integer channel, string name, key id, string msg)
{
if (channel == MENU_CHANNEL)
{
stopMenuListen();

if (msg == "Play Nice")
{
hMenu = llListen(MENU_CHANNEL, "", id, "");
llDialog(id, MENU_PROMPT, MENU_BUTTONS2, MENU_CHANNEL);
llSetTimerEvent(TIMEOUT_SECS);
llOwnerSay("You selected A");
}
if (msg == "Naughty")
{
hMenu = llListen(MENU_CHANNEL, "", id, "");
llDialog(id, MENU_PROMPT, MENU_BUTTONS3, MENU_CHANNEL);
llSetTimerEvent(TIMEOUT_SECS);
llOwnerSay("You selected Play Nice.");
}
if (msg == "Pull")
{
//Do something here
//llOwnerSay("You selected 1");
llSay(0,INSERT WHATEVER HERE);
}
if (msg == "Bite")
{
//Do something here
//llOwnerSay("You selected 2");
llSay(0,"test Bite");
}
if (msg == "Swat")
{
//Do something here
llOwnerSay("You selected 3");
llSay(0,"test Swat");
}
if (msg == "Kiss")
{
//Do something here
//llOwnerSay("You selected I");
llSay(0,"test Kiss");
}
if (msg == "Massage")
{
//Do something here
//llOwnerSay("You selected II");
llSay(0,"test Massage");
}
if (msg == "Rub")
{
//Do something here
//llOwnerSay("You selected III");
llSay(0,"test Rub");
}
}
}
timer()
{
stopMenuListen();
}
on_rez(integer start_param)
{
llResetScript();
}
}


The part that I am having problems with is this
llSay(0,INSERT WHATEVER HERE);

I want it to Say "Who" touched the "Owners" tail
with both names showing in main chat as part of that message.

Any ideas?
Laurence Corleone
Registered User
Join date: 12 Oct 2006
Posts: 126
12-12-2007 13:16
From: Jadon Christensen

The part that I am having problems with is this
llSay(0,INSERT WHATEVER HERE);

I want it to Say "Who" touched the "Owners" tail
with both names showing in main chat as part of that message.

Any ideas?


If I was gonna figure this out on my own, I would use a little logic. The first thing you want to do is find out (detect) who touched. This would have led me to here:
http://www.lslwiki.net/lslwiki/wakka.php?wakka=detected


where I would have checked out the detectedname function:
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llDetectedName


OK, so now I have the name of who touched it, but still need to get the owner's name. On that same page that I saw the detectedname function I also saw a detectedowner function. Cool, but this only gets me the owners key. Hmmm, I need to convert the owners key 2 a name. How cool, there is actually an llKey2Name function:
http://lslwiki.net/lslwiki/wakka.php?wakka=llKey2Name
.

Now that I have all the parts it is time to put it all together.

CODE

//string owner;
//owner = llGetOwner();

// Channel to listen for menu commands
integer MENU_CHANNEL = 9420133;

// Menu prompt and buttons
string MENU_PROMPT = "What do you want to do?";
list MENU_BUTTONS1 = ["Play Nice", "Naughty"];

// Sub Menus
list MENU_BUTTONS2 = ["Pull", "Bite", "Swat"];
list MENU_BUTTONS3 = ["Kiss", "Massage", "Rub"];

integer TIMEOUT_SECS = 20;
integer hMenu = -1;
showMenu(key id)
{
hMenu = llListen(MENU_CHANNEL, "", id, "");
llDialog(id, MENU_PROMPT, MENU_BUTTONS1, MENU_CHANNEL);
llSetTimerEvent(TIMEOUT_SECS);
}
stopMenuListen()
{
llSetTimerEvent(0);
if (hMenu != -1)
{
llListenRemove(hMenu);
hMenu = -1;
}
}
default
{
touch_start(integer num_detected)
{
integer i;
for (i = 0; i < num_detected; i++)
{
showMenu(llDetectedKey(i));
}
}
listen(integer channel, string name, key id, string msg)
{
if (channel == MENU_CHANNEL)
{
stopMenuListen();

if (msg == "Play Nice")
{
hMenu = llListen(MENU_CHANNEL, "", id, "");
llDialog(id, MENU_PROMPT, MENU_BUTTONS2, MENU_CHANNEL);
llSetTimerEvent(TIMEOUT_SECS);
llOwnerSay("You selected A");
}
if (msg == "Naughty")
{
hMenu = llListen(MENU_CHANNEL, "", id, "");
llDialog(id, MENU_PROMPT, MENU_BUTTONS3, MENU_CHANNEL);
llSetTimerEvent(TIMEOUT_SECS);
llOwnerSay("You selected Play Nice.");
}
if (msg == "Pull")
{
//Do something here
//llOwnerSay("You selected 1");
llSay(0,llDetectedName(0) + " pulled " + llKey2Name(llDetectedOwner(0)) + "'s tail.");
}
if (msg == "Bite")
{
//Do something here
//llOwnerSay("You selected 2");
llSay(0,"test Bite");
}
if (msg == "Swat")
{
//Do something here
llOwnerSay("You selected 3");
llSay(0,"test Swat");
}
if (msg == "Kiss")
{
//Do something here
//llOwnerSay("You selected I");
llSay(0,"test Kiss");
}
if (msg == "Massage")
{
//Do something here
//llOwnerSay("You selected II");
llSay(0,"test Massage");
}
if (msg == "Rub")
{
//Do something here
//llOwnerSay("You selected III");
llSay(0,"test Rub");
}
}
}
timer()
{
stopMenuListen();
}
on_rez(integer start_param)
{
llResetScript();
}
}


Hope that helps.
_____________________
There are no stupid questions, just stupid people.
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
12-12-2007 13:53
Detection functions aren't going to work in the listen Event Handler, so:

llSay(0, name + " pulled " + llKey2Name(llGetOwner()) + "'s tail.";);

...should do the trick.
Laurence Corleone
Registered User
Join date: 12 Oct 2006
Posts: 126
12-12-2007 21:28
From: Pale Spectre
Detection functions aren't going to work in the listen Event Handler, so:

llSay(0, name + " pulled " + llKey2Name(llGetOwner()) + "'s tail.";);

...should do the trick.


Thanks for correcting me Pale. I checked this in LSLEditor before posting and it worked there. Guess that will teach me for not double checking inworld too ;-)
_____________________
There are no stupid questions, just stupid people.
Jadon Christensen
Registered User
Join date: 24 Dec 2005
Posts: 32
12-13-2007 15:29
Thanks for the information guys. I will try this out a bit later.
Jaye Jeffries
Jaye Jeffries
Join date: 21 Oct 2006
Posts: 23
02-12-2008 21:18
Hi all,
this thread has already helped me a lot!
I have been trying to figure out how to have an interactive menu/submenu, that allows one to select a range of textures to be displayed onscreen.
Any idea how to go about this?
(please don't refer me to the scripts on the LSL portal, they are incredibly technical and I have already spent hours trying to get them to work!)

Thanks,
Jaye

[EDIT: Never mind, with the above scripts I have figured it out. Thanks a lot for those!]