llDialog Issue.
|
|
Puka Sorbet
Registered User
Join date: 7 Jun 2008
Posts: 5
|
06-12-2008 07:35
Hey, I promise this is a completely different subject to the thread that I just made  But, I'm trying to practice my scripting, and decided to start..."simple"...? What I'm trying to do is make a "Main Scipt", with which the user says ".activate.". Once they say that a Dialog box appears in the cornor of the screen (Very original...I know...), but for some reason the Dialog box isn't appearing at all. After fiddling around with the script for a while, it still dosen't seem to be working. Here is the script, and I really can't see what is wrong with it; //Integers integer Channel = 50; integer ShieldChannel = 51; integer ThemeChannel = 52; integer HelpChannel = 53; integer ScanChannel = 54; integer ExitChannel = 900;
//Lists list Menu_Main = ["Shield","Themes","Help","Scan","Exit"]; list Shield = ["On","Off","Exit"];
//Script: default { state_entry() { llListen(0,"",llGetOwner(),""); llListen(Channel,"",llGetOwner(),""); } listen(integer channel,string name,key id,string message) { if(channel == 0) { if(message == ".activate.") { llDialog(llDetectedKey(0),"Welcome to the Test Gadget \n Test Gadget v1.0 [Beta] \n --------- \n Main Menu \n Options:",["Shield","Themes","Help","Scan","Exit"],Channel); llListen(Channel,"",llGetOwner(),""); } } if(channel == 50) { if(message == "Shield") { llSay(ShieldChannel,"Open Shield Menu"); } if(message == "Themes") { llSay(ThemeChannel, "Open Theme Menu"); } if(message == "Help") { llSay(HelpChannel, "Open Help Menu"); } if(message == "Scan") { llSay(ScanChannel, "Open Scan Menu"); } } } }
But, then I wanted to have each section - As in the: if(message == "Shield") { llSay(ShieldChannel,"Open Shield Menu"); }
To activate another script in the gadget, to open up its own dialog window. So something a little like this; //Shield Script default { state_entry() { llListen(0,"",llGetOwner(),""); llListen(50, "",llGetOwner(),""); }
listen(integer channel, string name, key id, string message) { if(channel == 50) { if(message == "Shield") { llDialog(llDetectedKey(0),"Shield Menu",["On","Off"],50); llListen(50," ",llGetOwner(),""); } if(message == "On") { //Do Shield Script. } if(message == "Off") { //Do some more Shield Script. } } } }
But I tested all that, and it dosen't seem to be working. If anyone could help me with this that would be great. Thanks. P.S. Sorry If this is in the wrong section 
|
|
Shifting Dreamscape
Always questioning ...
Join date: 12 Dec 2007
Posts: 266
|
06-12-2008 07:43
As far as I can see with a quick read .. the problem seems to be your use of llDetectedKey(0) in th ellDialog call. That only works (I think) in a touch, in a listen there is nothing to detect. To fix this you have two options: 1) Since you are only listening to the owner ... llListen(0,"",llGetOwner(),""  ; llListen(Channel,"",llGetOwner(),""  ; You could just use the Owner's Key in the dialog call (btw instead of calling that over and over again, grab it once into a variable) 2) I believe that in a Listen, the passed id parameter is the key of whomever spoke on that channel ... so you could use that as well
|
|
Puka Sorbet
Registered User
Join date: 7 Jun 2008
Posts: 5
|
06-12-2008 07:52
From: Shifting Dreamscape As far as I can see with a quick read .. the problem seems to be your use of llDetectedKey(0) in th ellDialog call. That only works (I think) in a touch, in a listen there is nothing to detect. To fix this you have two options: 1) Since you are only listening to the owner ... llListen(0,"",llGetOwner(),""  ; llListen(Channel,"",llGetOwner(),""  ; You could just use the Owner's Key in the dialog call (btw instead of calling that over and over again, grab it once into a variable) 2) I believe that in a Listen, the passed id parameter is the key of whomever spoke on that channel ... so you could use that as well Where would I put; llListen(Channel,"",llGetOwner(),""  ;? As I put it over the; llDetectedKey(0), but the script didn't accept it. From: Shifting Dreamscape You could just use the Owner's Key in the dialog call (btw instead of calling that over and over again, grab it once into a variable)
How would I do this? Sorry for asking all the second questions! Thanks so far.
|
|
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
|
06-12-2008 09:09
I did not test this inworld... might need minor corrections: (use the quote-button of the forum to see the script with formatting) Your main Script:
//Integers integer gDlgChannel = -50; // Since you're listening to a Dialog-Menu, you should choose a negative channel' integer ShieldChannel = 51; integer ThemeChannel = 52; integer HelpChannel = 53; integer ScanChannel = 54; integer ExitChannel = 900;
integer gDialogListener; // Always provide a Link to your listeners, so you can delete them after you used them
key gOwner; // global Var for storing the Owner of the Object
//Lists list Menu_Main = ["Shield","Themes","Help","Scan","Exit"]; // You repeated this in your llDialog-Call - I replaced it with the list-variable you provide here list Shield = ["On","Off","Exit"];
//Script: default { state_entry() { gOwner = llGetOwner(); llListen(0,"",gOwner,""); //llListen(Channel,"",llGetOwner(),""); // Not needed since this listener only needs to be triggered, when the main menu pops up } listen(integer channel,string name,key id,string message) { if(channel == 0 && id == gOwner) { if(message == ".activate.") { llDialog(gOwner,"Welcome to the Test Gadget \n Test Gadget v1.0 [Beta] \n --------- \n Main Menu \n Options:", Menu_Main, gDlgChannel); gDialogListener = llListen(gDlgChannel,"",gOwner,""); // Now it's time to listen to llDialog' llSetTimerEvent(30); //Initialize a Timer to close the listener, in case the user hits «ignore» } } if(channel == gDlgChannel && id == gOwner) { llListenRemove(gDialogListener); // The user made a selection, so we don't need the listener anymore' // if the other script is in the same object, than this script, you can use Linked Messages to call it up if(message == "Shield") { llMessageLinked(LINK_THIS, 0, "Shield", gOwner); //llSay(ShieldChannel,"Open Shield Menu"); } if(message == "Themes") { llSay(ThemeChannel, "Open Theme Menu"); } if(message == "Help") { llSay(HelpChannel, "Open Help Menu"); } if(message == "Scan") { llSay(ScanChannel, "Open Scan Menu"); } } } timer(){ // timer event gets triggered so we can lose the listener llListenRemove(gDialogListener); llSetTimerEvent(0); } }
// Your slave-script for the shield-menu //Shield Script
key gOwner; // Global var to store the owner's-key
integer gDialogChannel = -100; // Global var for the Dialog-Channel integer gDialogListener;
default { state_entry() { gOwner = llGetOwner(); }
link_message(integer sender, integer num, string str, key id){ if(str == "Shield"){ llDialog(gOwner, "Shield Menu", ["On", "Off"], gDialogChannel); gDialogListener = llListen(gDialogChannel, "", gOwner, ""); // Set up the listener for the Dialog llSetTimerEvent(30); // Set up a timer event in case the user hits «ignore» } }
listen(integer channel, string name, key id, string message) { if(channel == gDialogChannel && id == gOwner) { llListenRemove(gDialogListener); // Remove the listener if(message == "On") { //Do Shield Script. } if(message == "Off") { //Do some more Shield Script. } } } // Remove the Listener after 30 Seconds if the user didn't respond timer(){ llSetTimerEvent(0); llListenRemove(gDialogListener); // Remove the listener } }
Hope, this is not too confusing 
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
06-12-2008 11:27
Yes, llDetected functions only work with touch, collision, and sensor events. I modified your script so that it now works, I commented the changes and explained the reason for the changes, so it's pretty self explanatory. Your original script as written would have worked if not for the llDetected mistake, but is way laggy, read the comments and you'll better understand how to work listens so they're as lag free as possible. Also, you double defined a listen, which is not needed, I commented it out but left it there to show you were your mistake was and commented it, so... //Integers integer Channel = 50; integer ShieldChannel = 51; integer ThemeChannel = 52; integer HelpChannel = 53; integer ScanChannel = 54; integer ExitChannel = 900; key avatar; // <--- define a variable to hold avatar's key //Lists list Menu_Main = ["Shield","Themes","Help","Scan","Exit"]; list Shield = ["On","Off","Exit"];
//Script: default { on_rez (integer foo) // add this event to reset and read new owner if item is transfered. { llResetScript(); } state_entry() { avatar = llGetOwner(); // Grab the avatar's key here... llListen(0,"",llGetOwner(),".activate."); // also notice the addition of ".activate." in the message filter, it's the only open chat you're listening for // so why not filter for it to reduce lag while open channel listen is open. When it comes to listens, it's // always best to filter as much as possible. Since you're only listening for one command, set the message filter // to listen for only that. llListen(Channel,"",llGetOwner(),""); } listen(integer channel,string name,key id,string message) { if (channel == 0) { llDialog(avatar,"Welcome to the Test Gadget \n Test Gadget v1.0 [Beta] \n --------- \n Main Menu \n Options:",["Shield","Themes","Help","Scan","Exit"],Channel); // note key in llDialog changed to avatar variable
// llListen(Channel,"",llGetOwner(),""); // You already defined ^ this listen, why define it again? } if(channel == 50) { if(message == "Shield") { llSay(ShieldChannel,"Open Shield Menu"); } if(message == "Themes") { llSay(ThemeChannel, "Open Theme Menu"); } if(message == "Help") { llSay(HelpChannel, "Open Help Menu"); } if(message == "Scan") { llSay(ScanChannel, "Open Scan Menu"); } } } }
http://www.secondscripter.com/
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
|
Puka Sorbet
Registered User
Join date: 7 Jun 2008
Posts: 5
|
06-12-2008 12:24
Thank you all for your help!
|