Resilient Posted June 26, 2011 Share Posted June 26, 2011 I have done the first dialog menu with Dance options. I want a sub menu to be formed when I click on any of the options on the first menu showing the names of detected avatars around. Can anyone help me with this? Link to comment Share on other sites More sharing options...
Resilient Posted June 26, 2011 Author Share Posted June 26, 2011 string msg = "What do you want to do?"; list dances = ["Dance1","Dance2","Dance3"]; integer channel=-10; key ToucherID; integer listen_id; default { touch_start(integer total_number) { ToucherID = llDetectedKey(0); llDialog(ToucherID, msg, dances, channel); listen_id = llListen( channel, "", ToucherID, ""); llSetTimerEvent(60); } listen(integer channel, string name, key id, string choice) { if (choice == "Dance1") { llDialog(ToucherID, 2ndmenumsg, *(avatarsDetected)*, channel);[this is where I need to detect the avs and make them appear as a list for the 2nd menu] } llListenRemove(listen_id); } else if (choice == "Dance2") {and so on.. Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 26, 2011 Share Posted June 26, 2011 So, make yourself a flow diagram to see the logic: 1. llDialog in touch_start event asks for dance choice. 2. Choice is heard in listen event, triggers llSensor 3. sensor event detects avatars, opens new llDialog to choose a specific avatar. 4. Choice is heard in listen event, triggers llRequestPermissions(avKey,PERMISSION_TRIGGER_ANIMATION) 5. Chosen av receives permission request, and accepts 6. run_time_permissions verifies permission, llStartAnimation("chosen_animation"). BTW, to make your scripts easier to read in the forum, cut&paste them into the code window that opens when you click the icon that looks like a folder with a letter C on it, just above the edit window here. 1 Link to comment Share on other sites More sharing options...
Resilient Posted June 26, 2011 Author Share Posted June 26, 2011 I had thought of the same logic too but I had got an error in syntax right before the event sensor, can you help me why i am getting this or my code not working key ToucherID;string msg = "Choose your dance";list dances = ["Dance1","Dance2","Dance3"];integer channel = -10;integer listen_id;string menuText = "Select your target:";list avatarsDetected = [ ];list keysDetected = [ ];default{touch_start(integer total_number){ ToucherID = llDetectedKey(0); llDialog(ToucherID, msg, dances, channel); listen_id = llListen(channel, "", ToucherID, ""); llSetTimerEvent(60);}listen(integer channel, string name, key id, string choice) {if (choice == "Dance1") { llSensor("", NULL_KEY, AGENT, 50, PI);}{sensor(integer numDetected); //line number 26{if (numDetected > 12) numDetected = 12;integer nextStep;string nextAvatarName;string nextAvatarKey;avatarsDetected = [ ];keysDetected = [ ];for (nextStep = 0; nextStep < numDetected; nextStep++){ nextAvatarName = llDetectedName(nextStep);nextAvatarKey = llDetectedKey(nextStep);if (llStringLength(nextAvatarName) > 24) nextAvatarName = llGetSubString(nextAvatarName, 0, 23);avatarsDetected = (avatarsDetected=[]) + avatarsDetected + nextAvatarName; keysDetected = (keysDetected=[]) + keysDetected + nextAvatarKey; }}llDialog(ToucherID, menuText, avatarsDetected, channel);llListenRemove(listen_id); }}} (26,0):Error:Syntax Error Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted June 26, 2011 Share Posted June 26, 2011 there shouldn't be a ; at the end of the sensor event line. ETA If you make it indented, it's much easier to read Link to comment Share on other sites More sharing options...
Resilient Posted June 26, 2011 Author Share Posted June 26, 2011 that was dumb of me but I removed the semi colon and it still gives the same error I will make it sandwiched from now on, thanks Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted June 26, 2011 Share Posted June 26, 2011 you better do - I'm sure it's the main reason for your brace massacre key ToucherID;string msg = "Choose your dance";list dances = ["Dance1","Dance2","Dance3"];integer channel = -10;integer listen_id;string menuText = "Select your target:";list avatarsDetected = [ ];list keysDetected = [ ];default{touch_start(integer total_number){ ToucherID = llDetectedKey(0); llDialog(ToucherID, msg, dances, channel); listen_id = llListen(channel, "", ToucherID, ""); llSetTimerEvent(60);}listen(integer channel, string name, key id, string choice) {if (choice == "Dance1") { llSensor("", NULL_KEY, AGENT, 50, PI);}}sensor(integer numDetected) //line number 26{if (numDetected > 12) numDetected = 12;integer nextStep;string nextAvatarName;string nextAvatarKey;avatarsDetected = [ ];keysDetected = [ ];for (nextStep = 0; nextStep < numDetected; nextStep++){ nextAvatarName = llDetectedName(nextStep);nextAvatarKey = llDetectedKey(nextStep);if (llStringLength(nextAvatarName) > 24) nextAvatarName = llGetSubString(nextAvatarName, 0, 23);avatarsDetected = (avatarsDetected=[]) + avatarsDetected + nextAvatarName; keysDetected = (keysDetected=[]) + keysDetected + nextAvatarKey; }llDialog(ToucherID, menuText, avatarsDetected, channel);llListenRemove(listen_id); }} There have been some more 1 Link to comment Share on other sites More sharing options...
Resilient Posted June 26, 2011 Author Share Posted June 26, 2011 Thank you so much Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 26, 2011 Share Posted June 26, 2011 Here's another suggestion...... I know that it's really nice to be able to leave out the { } brackets when you only have one statement immediately following an if test, but don't make it a habit. It won't be long before you forget and add a second statement to your if test, and it won't work because that one won't be bracketed. Always bracket all scopes in your script, even if they aren't technically required. Link to comment Share on other sites More sharing options...
Resilient Posted June 27, 2011 Author Share Posted June 27, 2011 Thank you , will note that Link to comment Share on other sites More sharing options...
Resilient Posted June 27, 2011 Author Share Posted June 27, 2011 I got stuck again.. cant figure out a way around this key ToucherID;string msg = "Choose your dance";list dances = ["Dance1","Dance2","Dance3"];integer channel = -10;integer listen_id;integer listen_idd;string menuText = "Select your target:";list avatarsDetected = [ ];list keysDetected = [ ];key avKey;default{ touch_start(integer total_number) { ToucherID = llDetectedKey(0); llDialog(ToucherID, msg, dances, channel); listen_id = llListen(channel, "", ToucherID, ""); llSetTimerEvent(60); } listen(integer channel, string name, key id, string choice) { if (choice == "Dance1") { llSensor("", NULL_KEY, AGENT, 100, PI); } } sensor(integer numDetected) {if (numDetected > 2) numDetected = 2;integer nextStep;string nextAvatarName;string nextAvatarKey;avatarsDetected = [ ];keysDetected = [ ];for (nextStep = 0; nextStep < numDetected; nextStep++) { nextAvatarName = llDetectedName(nextStep); nextAvatarKey = llDetectedKey(nextStep); if (llStringLength(nextAvatarName) > 24) nextAvatarName = llGetSubString(nextAvatarName, 0, 23); avatarsDetected = (avatarsDetected=[]) + avatarsDetected + nextAvatarName; keysDetected = (keysDetected=[]) + keysDetected + nextAvatarKey; }llDialog(ToucherID, menuText, avatarsDetected, channel);listen_idd = llListen(channel, "", ToucherID, ""); }listen(integer channel, string name, key id, string nextavatarName) //(54,58):Error: Name previously declared within scope ... right after choice{ string zero=llList2String(avatarsDetected, 0); string one=llList2String(avatarsDetected, 1); if (nextavatarName == zero ) { avKey=llList2String(keysDetected, 0); llRequestPermissions(avKey,PERMISSION_TRIGGER_ANIMATION); }} run_time_permissions(integer perm) { if (perm & PERMISSION_TRIGGER_ANIMATION) { llStartAnimation("dance1"); } } } Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted June 27, 2011 Share Posted June 27, 2011 You define a global called 'channel' in line 4. There is another integer variable called 'channel' declared in line 55 - the two collide. That's one thing. The other is: You have two listen events line 25 and 55. You should really get a decent editor - that would tell you such stuff. 1 Link to comment Share on other sites More sharing options...
Resilient Posted June 27, 2011 Author Share Posted June 27, 2011 thanks but couldn't there be 2 listen events? Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted June 27, 2011 Share Posted June 27, 2011 you can have only one occurence of an event per state - anything else doesn't really make sennse Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 27, 2011 Share Posted June 27, 2011 Never. You can only have one event of each type in a state. Combine your two listen events into one. 1 Link to comment Share on other sites More sharing options...
Void Singer Posted June 27, 2011 Share Posted June 27, 2011 you can listen on more than one channel, but they will all trigger the same listen event. 1 Link to comment Share on other sites More sharing options...
Resilient Posted June 28, 2011 Author Share Posted June 28, 2011 key ToucherID;string msg = "Choose your dance";list dances = ["Dance1","Dance2","Dance3"];integer channela = -10;integer channelb = -20;integer listen_id;string menuText = "Select your target:";list avatarsDetected = [ ];list keysDetected = [ ];string zero;string one;default{touch_start(integer total_number){ ToucherID = llDetectedKey(0); llDialog(ToucherID, msg, dances, channela); listen_id = llListen(channela, "", ToucherID, ""); llSetTimerEvent(60);}listen(integer channel, string name, key id, string choice) { if(channel == channela) { if (choice == "Dance1") { llSensor("", NULL_KEY, AGENT, 50, PI); } else if (choice=="Dance2") { llSensor("",NULL_KEY, AGENT, 50, PI ); } else if (choice=="Dance3") { llSensor("",NULL_KEY, AGENT, 50, PI ); } } else if(channel==channelb) { } }sensor(integer numDetected){if (numDetected > 2) numDetected = 2;integer nextStep;string nextAvatarName;string nextAvatarKey;avatarsDetected = [ ];keysDetected = [ ];for (nextStep = 0; nextStep < numDetected; nextStep++){ nextAvatarName = llDetectedName(nextStep);nextAvatarKey = llDetectedKey(nextStep);if (llStringLength(nextAvatarName) > 24) nextAvatarName = llGetSubString(nextAvatarName, 0, 23);avatarsDetected = (avatarsDetected=[]) + avatarsDetected + nextAvatarName; keysDetected = (keysDetected=[]) + keysDetected + nextAvatarKey; }llDialog(ToucherID, menuText, avatarsDetected, channelb);listen_id = llListen(channelb, "", ToucherID, ""); }} I tried my best to combine the 2 listens however I do have two queries 01. How do I extract the detected avatar names as choices for the second time i.e. in channelb 02. How do I match the correct animation(choices for the first time i.e. in channela) to the detected avatar? Any help is much appreciated. Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 28, 2011 Share Posted June 28, 2011 You'll have to store both sets of data in lists and then use list functions like llListFindList to get the elements you want. Link to comment Share on other sites More sharing options...
Resilient Posted June 28, 2011 Author Share Posted June 28, 2011 key ToucherID;string msg = "Choose your dance";list dances = ["Dance1","Dance2","Dance3"];integer channela = -10;integer channelb = -20;integer listen_id;string menuText = "Select your target:";list avatarsDetected = [ ];list keysDetected = [ ];integer index;integer indexx;default{touch_start(integer total_number){ ToucherID = llDetectedKey(0); llDialog(ToucherID, msg, dances, channela); listen_id = llListen(channela, "", ToucherID, ""); llSetTimerEvent(60);}listen(integer channel, string name, key id, string choice) { if(channel == channela) { if (choice == "Dance1") { llSensor("", NULL_KEY, AGENT, 50, PI); } else if (choice=="Dance2") { llSensor("",NULL_KEY, AGENT, 50, PI ); } else if (choice=="Dance3") { llSensor("",NULL_KEY, AGENT, 50, PI ); } } else if(channel==channelb) { integer index = llListFindList(avatarsDetected, []); if (index != -1) { integer indexx = llListFindList(dances, []); // I know this part is wrong but cant think of how to solve this if (indexx==0) { llOwnerSay("hi"); } else if (indexx==1) { llOwnerSay("bye"); } } } }sensor(integer numDetected){if (numDetected > 2) numDetected = 2;integer nextStep;string nextAvatarName;string nextAvatarKey;avatarsDetected = [ ];keysDetected = [ ];for (nextStep = 0; nextStep < numDetected; nextStep++){ nextAvatarName = llDetectedName(nextStep);nextAvatarKey = llDetectedKey(nextStep);if (llStringLength(nextAvatarName) > 24) nextAvatarName = llGetSubString(nextAvatarName, 0, 23);avatarsDetected = (avatarsDetected=[]) + avatarsDetected + nextAvatarName; keysDetected = (keysDetected=[]) + keysDetected + nextAvatarKey; }llDialog(ToucherID, menuText, avatarsDetected, channelb);listen_id = llListen(channelb, "", ToucherID, ""); }} Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 28, 2011 Share Posted June 28, 2011 OK..... Your logic is all turned around, and you're having trouble with the LSL too, so you're getting confused. Here's one way to do what you want (untested in world, but it compiles so at least the LSL is valid) .......... key ToucherID;list dances = ["Dance1","Dance2","Dance3"];integer channela = -10;integer channelb = -20;integer listen_id;string menuText = "Select your target:";integer gChoice;list gAvNames;list gAvKeys; default{ touch_start(integer total_number) { ToucherID = llDetectedKey(0); listen_id = llListen(channela, "", ToucherID, ""); //Open listen channel first.... llDialog(ToucherID, "Choose your dance", dances, channela); // Then open dialog llSetTimerEvent(60.0); // Set a timer for timeouts } timer() { //timeout llSetTimerEvent(0.0); //Shut off the timer llListenRemove(listen_id); // Kill the open listen handle } listen(integer channel, string name, key id, string msg) { if(channel == channela) { llListenRemove(listen_id); // Remove the dialog listener gChoice = llListFindList(dances, [msg]); //gChoice is the position of msg in your list of dances llSensor("",NULL_KEY, AGENT, 50.0, PI ); // Look for a partner (kinda far away.....) } else if(channel==channelb) { llListenRemove(listen_id);// Remove the dialog listener integer idx = llListFindList(gAvNames,[msg]); // Where is the chosen partner's name (msg) in the list of choices? // Gotta ask permission now ........ llRequestPermissions(llList2Key(gAvKeys,idx),PERMISSION_TRIGGER_ANIMATION); //llList2Keys(gAvKeys,idx) is the UUID of the chosen partner } } run_time_permissions(integer perm) { if(perm & PERMISSION_TRIGGER_ANIMATION) /// If your partner accepted ....... { llStartAnimation(llList2String(dances,gChoice)); // This is the particular dance you chose, remember? } } sensor(integer numDetected) { gAvNames = []; //Empty these lists of previous information gAvKeys = []; integer i; for (i=0;i<numDetected;++i) { gAvNames += [llGetSubString(llDetectedName(i),0,23)]; //Store truncated names gAvKeys += [llDetectedKey(i)]; //And UUIDs } llSetTimerEvent(60.0); // set timer for timeout listen_id = llListen(channelb, "", ToucherID, ""); // Re-open the chat channel llDialog(ToucherID, "Want to dance?", gAvNames, channelb); //Ask partner }} You don't need to listen on two different channels, but that's certainly one way to do it. You could just as easily filter the responses instead. As written, this script assumes that you actually have dances named "Dance1", "Dance2", and "Dance3". Those names are doing double duty as the button labels for your first dialog. If the dances actually have other names, you can still use these button labels, but you'll need to read the dance names from another, parallel list. BTW, setting the sensor to look out 50.0m means you might get a LOT of hits and overwhelm the llDialog. You're less likely to have more than the 12 button max if you scan over, say, 15 or 20m. Of course, you could always add extra dialog pages ..... :smileywink: ETA: Forgot to set the timer again before the second dialog. Fixed. 1 Link to comment Share on other sites More sharing options...
Resilient Posted June 28, 2011 Author Share Posted June 28, 2011 Thank you so much. It works Link to comment Share on other sites More sharing options...
Rolig Loon Posted June 28, 2011 Share Posted June 28, 2011 Neat! Now try taking it apart again, adding bells and whistles, and trying different ways to do the same thing. When you are learning, it's sometimes easier to start with something that you know works already, so that you have a place to go back to when you break it. Have fun. Oh, and at least while you are learning: (1) Remember that neatness counts (intent, match all brackets, ....) (2) Load your script full of comments, so that the logic that's in your head gets out in print where you can see it. (3) Don't be afraid to ask for help, but try and figure it out yourself first. Link to comment Share on other sites More sharing options...
Resilient Posted June 29, 2011 Author Share Posted June 29, 2011 yes , I did pick up the importance of indenting , making comments and will surely ask when I get stuck again. Thanks for all the help. Link to comment Share on other sites More sharing options...
Resilient Posted July 21, 2011 Author Share Posted July 21, 2011 was away from SL for a while but came back and played with this script , I added a new thing to it but can you tell me why it is not working , it compiles but does not give me the required output, i made comments at the end of the script where i added the 5 lines of code myself key ToucherID;list dances = ["Dance1","Dance2","Dance3"];integer channela = -10;integer channelb = -20;integer listen_id;string menuText = "Select your target:";integer gChoice;list gAvNames;list gAvKeys; integer z;default{ touch_start(integer total_number) { ToucherID = llDetectedKey(0); listen_id = llListen(channela, "", ToucherID, ""); //Open listen channel first.... llDialog(ToucherID, "Choose your dance", dances, channela); // Then open dialog llSetTimerEvent(60.0); // Set a timer for timeouts } timer() { //timeout llSetTimerEvent(0.0); //Shut off the timer llListenRemove(listen_id); // Kill the open listen handle } listen(integer channel, string name, key id, string msg) { if(channel == channela) { llListenRemove(listen_id); // Remove the dialog listener gChoice = llListFindList(dances, [msg]); //gChoice is the position of msg in your list of dances llSensor("",NULL_KEY, AGENT, 50.0, PI ); // Look for a partner (kinda far away.....) } else if(channel==channelb) { llListenRemove(listen_id);// Remove the dialog listener integer idx = llListFindList(gAvNames,[msg]); // Where is the chosen partner's name (msg) in the list of choices? // Gotta ask permission now ........ llRequestPermissions(llList2Key(gAvKeys,idx),PERMISSION_TRIGGER_ANIMATION); //llList2Keys(gAvKeys,idx) is the UUID of the chosen partner } } run_time_permissions(integer perm) { if(perm & PERMISSION_TRIGGER_ANIMATION) /// If your partner accepted ....... { llStartAnimation(llList2String(dances,gChoice)); // This is the particular dance you chose, remember? } } sensor(integer numDetected) { gAvNames = []; //Empty these lists of previous information gAvKeys = []; integer i; for (i=0;i<numDetected;++i) { gAvNames += [llGetSubString(llDetectedName(i),0,23)]; //Store truncated names gAvKeys += [llDetectedKey(i)]; //And UUIDs } integer z = llGetListLength(gAvNames); // these are the 5 lines that I added so that if no one is near the hud will say something back to me if (z<1) // it compiles too but it does not say it when no one is near { // llOwnerSay("no one to dance with.");// } // llSetTimerEvent(60.0); // set timer for timeout listen_id = llListen(channelb, "", ToucherID, ""); // Re-open the chat channel llDialog(ToucherID, "Want to dance?", gAvNames, channelb); //Ask partner }} Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted July 21, 2011 Share Posted July 21, 2011 there are 2 problems I can see: z < 1: z is always 1 because you are detected - so you should avoid your name being added to the list of avas the dialog will alwys be shown since the call to llDialog is not part of the if statement Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now