Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dialogue Menu Question

Nathan Babcock
Registered User
Join date: 5 May 2006
Posts: 47
11-30-2006 16:20
Hello,

I am new to scripting although I have been building items for fun. I need help with a dialogue menu script that has 5 options, and each option calls another script in the same object.

Example:

When the owner clicks on the object this menu appears:
Menu - Email, Music, Video, Calculator, etc.

When they select: Email
It calls my email script in the same object.

What code do I need to place in my email script (currectly called by touch) and how do I setup the menu script?

Please help me if you can.

Thank you!!
Nathan
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
11-30-2006 16:42
dialogs get returned in a listen event so for each script you will need to setup a listener

llListen(integer chat channel, string name, key id, string msg)

where it says string message put in something like "email"

this way only the e-mail script will hear the message ...

course you will need to setup your chat channel and any other filters you may want

in the scripts you will need to change the touch or touch_start() events with a listen event

listen(integer channel, string name, key id, string message)
{
llDoStuff();
}
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
11-30-2006 16:45
Use llMessageLinked to transmitt the data to the other scripts and a link_message in the receiving scripts to hear the requests
Nathan Babcock
Registered User
Join date: 5 May 2006
Posts: 47
12-01-2006 04:50
Thank you - I will try doing all this today and see if i can get it running!
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
12-01-2006 06:05
From: Osgeld Barmy
dialogs get returned in a listen event so for each script you will need to setup a listener

llListen(integer chat channel, string name, key id, string msg)

where it says string message put in something like "email"

this way only the e-mail script will hear the message ...

course you will need to setup your chat channel and any other filters you may want

in the scripts you will need to change the touch or touch_start() events with a listen event

listen(integer channel, string name, key id, string message)
{
llDoStuff();
}

Avoiding multiple listeners (I haven't checked if this is error-free since I'm at class):

CODE

integer listener = 0;
integer channel = 0;

string dialog_msg = "Insert popup dialog msg here.";
list dialog_buttons = ["Button1", "Button2", "Button3", "Button4", "Button5"];
float dialog_timeout = 15.;

default
{
touch_start(integer number) {
if (llDetectedKey(0) == llGetOwner()) {
channel = llCeil(llFrand(2000000.) + 1000.);
listener = llListen(channel, "", llGetOwner(), "");
llSetTimerEvent(dialog_timeout);
llDialog(llGetOwner(), dialog_msg, dialog_buttons, channel);
}
}

listen(integer channel, string name, key id, string msg) {
llSetTimerEvent(0.);
llListenRemove(listener);
llMessageLinked(LINK_SET, 0, "", msg);
}

timer() {
llSetTimerEvent(0.);
llListenRemove(listener);
llOwnerSay("Menu timing out.");
}
}


Then put a receiving link message event in each of your scripts to handle the various functions of the buttons. This is also a cheapo example of how to do listens that only open for the dialog and time out (after 15 seconds in this example).
_____________________
Nathan Babcock
Registered User
Join date: 5 May 2006
Posts: 47
12-01-2006 06:42
Tyken,

Thanks for your help! So If I create an object andp lace your snippet for dialogue box in it, and then place the email code in the same object. I need to change the "touch start" part of the script to:

link_message(integer sender_num, integer num, string str, key id)

So that the code activates when your script sends the LinkedMessage? Now here is the snippet wheere the edit occurs in the email script:

---

touch_start(integer total_number)
{
senderKey = llDetectedKey(0);
senderName = llKey2Name(llDetectedKey(0));
llDialog(senderKey, "Greetings " + senderName + ", would you like to send an email?", sendButtons, 67895);

---

So when I changed it to this, nothing happens:

---

link_message(integer sender_num, integer num, string str, key id)
{
senderKey = llDetectedKey(0);
senderName = llKey2Name(llDetectedKey(0));
llDialog(senderKey, "Greetings " + senderName + ", would you like to send an email?", sendButtons, 67895);

---

I envy you tech geeks! I want to code, you either have it or you dont I geuss. Please let me know what i did wrong?

Nathan
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
12-01-2006 07:39
From: Nathan Babcock
Tyken,

Thanks for your help! So If I create an object andp lace your snippet for dialogue box in it, and then place the email code in the same object. I need to change the "touch start" part of the script to:

link_message(integer sender_num, integer num, string str, key id)

So that the code activates when your script sends the LinkedMessage? Now here is the snippet wheere the edit occurs in the email script:

---

touch_start(integer total_number)
{
senderKey = llDetectedKey(0);
senderName = llKey2Name(llDetectedKey(0));
llDialog(senderKey, "Greetings " + senderName + ", would you like to send an email?", sendButtons, 67895);

---

So when I changed it to this, nothing happens:

---

link_message(integer sender_num, integer num, string str, key id)
{
senderKey = llDetectedKey(0);
senderName = llKey2Name(llDetectedKey(0));
llDialog(senderKey, "Greetings " + senderName + ", would you like to send an email?", sendButtons, 67895);

---

I envy you tech geeks! I want to code, you either have it or you dont I geuss. Please let me know what i did wrong?

Nathan

The snipper should work as-is, on its own script. What happens is thus:
  1. The owner touches the object.
  2. This script opens a listen, and pops up a dialog using the appropriate channel.
  3. The owner clicks a button, and the button's text is sent to the listen event in this same script.
  4. This script receives that text label and sends it out in a link message to whatever other scripts are in the object.
  5. Your individual function scripts receive this link message in their own link_message events.
  6. Within those scripts' link_message events, you handle whatever they need to do.


So you could have a bunch of extra scripts that only have link_message events and whatever else they need to function. In their link_message events, you just put a simple check to see if their corresponding button was pressed, like if (message == "Email";) { blah blah..; }.

Also, we tech geeks charge by the hour. :)
_____________________
Nathan Babcock
Registered User
Join date: 5 May 2006
Posts: 47
12-01-2006 18:35
If i add:

if(message == "Email";)

It gives me an error "not defined in scope. Help ! ;-/
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
12-01-2006 19:13
From: Nathan Babcock
If i add:

if(message == "Email";)

It gives me an error "not defined in scope. Help ! ;-/

You have to be more specific about what you're adding where.
_____________________
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-02-2006 06:19
Nathan,

hopefully i wont confuse the issue, but here is how I would (and have) approach the idea :-

Main Menu Script
Main Menu - just passes on primary selections to child scripts

CODE

list MenuChoices = ["Email", "Music", "Video", "Calculator"];
integer Listening = 0;
integer listenchannel = 0;

UpdateListen(key id)
{
CancelListen();
Listening = llListen(listenchannel,"",id,"");
llSetTimerEvent(30);
}

CancelListen()
{
if(Listening > 0) llListenRemove(Listening);
Listening = 0;
llSetTimerEvent(0);
}

// Owner Conversation Dialog
ShowMenu(key id)
{
listenchannel = - (integer)llFrand(2147483648);
string text = "Menu\nPlease Select an Option";
// finally show the dialog
llDialog(id,text,MenuChoices,listenchannel);
UpdateListen(id);
}


// States
default
{
state_entry()
{
llSetTimerEvent(0);
}

on_rez(integer num) { llResetScript(); }

changed(integer change)
{
// something changed
if (change & CHANGED_INVENTORY)
{
llResetScript();
}
}

touch_start(integer total_number)
{
// Owner
key id = llDetectedKey(0);
if( (id == llGetOwner()))
{
listenchannel = (integer)llFrand(1000) + 10;
ShowMenu(id);
}
}

timer()
{
CancelListen();
}

listen( integer channel, string name, key id, string message )
{
CancelListen();
llMessageLinked(LINK_THIS,0,message, id);

}
}


Child Scripts
The child script will receive a linked message detailing the request and ID of the user

CODE

string function = "Video";

list MenuChoices = ["Video 1", "Video 2", "Video 3", "Video 4"];
integer Listening = 0;
integer listenchannel = 0;

UpdateListen(key id)
{
CancelListen();
Listening = llListen(listenchannel,"",id,"");
llSetTimerEvent(30);
}

CancelListen()
{
if(Listening > 0) llListenRemove(Listening);
Listening = 0;
llSetTimerEvent(0);
}

// Owner Conversation Dialog
ShowMenu(key id)
{

listenchannel = - (integer)llFrand(2147483648);
string text = "Menu\nPlease Select an Option";
// finally show the dialog
llDialog(id,text,MenuChoices,listenchannel);
UpdateListen(id);
}


// States
default
{
state_entry()
{
llSetTimerEvent(0);
}

on_rez(integer num) { llResetScript(); }

link_message(integer sender_num, integer num, string str, key id)
{
// Handle command from master script
if(str == function)
{
ShowMenu(id);
}
}

timer()
{
CancelListen();
}

listen( integer channel, string name, key id, string message )
{
CancelListen();
// Process our own messages

}
}


As you can see there is a lot of common code, which could be parcelled out to a single Menu handler script that acts on behalf of the individual scripts via linked messages.
Nathan Babcock
Registered User
Join date: 5 May 2006
Posts: 47
12-05-2006 12:36
I figured this out thank you so much for all your help. Took a while but basically the link message came through, but the AV key was not defined properly so it was not responding to me - or anyone....i geuss. Hope this makes sense.