Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help with menu script

Myhrrhleine Wingtips
Registered User
Join date: 10 Mar 2008
Posts: 29
06-18-2008 08:27
I am currently working on a greeter hud and need a little help.

Currently when the hud is clicked it scans the area for nearby avatars and presents a list, when a name is selected from teh menu it says somethign in open chat. What I would like to do is be able via dialog be able to select what is said in chat. I currently have it working with a single message per prim, but I would like to be able to do more messages within a single prim. Any help would be greatly appreciated.

Thanks in advance.
Myhrrhleine Wingtips
Registered User
Join date: 10 Mar 2008
Posts: 29
06-20-2008 05:54
Ok I have managed to cobble the script together, but for some reason it does not seem to be working correctly. When I had my states set up and was hard coding the data it worked fine, but as soon as I added the dialogs everything went haywire. Its as though its jumping through my states out of the order I intend. Any help would be greatly appreciated. This is my first attempt at using both lists and dialogs so please be kind.


CODE


string Avatar;
string Action;

integer CHANNEL = -42; // dialog channel
list MENU_MAIN = ["Sit", "Stand", "Fly", "Cheat"]; // the main menu

string menuText = "Select your target:";
list avatarsDetected = [ ];
string firstname = "";


default
{
on_rez(integer start_param)
{
llOwnerSay("Resetting");
llResetScript();
}


state_entry()
{

state idle;
}

}


state idle{

state_entry()
{
llOwnerSay("Entering Idle");//For Debug

}

touch_start(integer total_number)
{

state GetAvatars;
}
}


state GetAvatars{

state_entry()
{
llOwnerSay("Entering GetAvatars");//For Debug

llListen(CHANNEL, "", llGetOwner(), "");
}

listen(integer channel, string name, key id, string xmessage)
{
integer listPos = llListFindList(avatarsDetected, (list)xmessage);
firstname = llGetSubString(xmessage, 0, llSubStringIndex(xmessage, " ") - 1);


llSensor("", NULL_KEY, AGENT, 30, PI);


}

sensor(integer numDetected)
{
if (numDetected > 12) numDetected = 12;
integer nextStep;
string nextAvatarName;
avatarsDetected = [ ];
for (nextStep = 0; nextStep < numDetected; nextStep++)
{
nextAvatarName = llDetectedName(nextStep);
if (llStringLength(nextAvatarName) > 24) nextAvatarName = llGetSubString(nextAvatarName, 0, 23);
avatarsDetected = (avatarsDetected=[]) + avatarsDetected + nextAvatarName;
}
llDialog(llGetOwner(), menuText, avatarsDetected, CHANNEL);

Avatar = firstname;


state SelectAction;
}
}


state SelectAction{
state_entry() {

llOwnerSay("Entering SelectAction");//For Debug

llListen(CHANNEL, "", NULL_KEY, "");

llDialog(llDetectedKey(0), "What do you want to do?", MENU_MAIN, CHANNEL); }

listen(integer channel, string name, key id, string message)
{
if (llListFindList(MENU_MAIN , [message]) != -1) // verify dialog choice

{

Action = message;
}
state DoAction;
}
}


state DoAction{
state_entry()
{
llOwnerSay("Entering DoAction");//For Debug

//ToDo: Insert Do stuff with selections here

llSay(0, Avatar + " Does " + Action);
state idle;
}
}

Kahiro Watanabe
Registered User
Join date: 28 Sep 2007
Posts: 572
06-20-2008 06:27
It's a common mistake...llDetected... functions works only on:

touch,senor and colission events

http://lslwiki.net/lslwiki/wakka.php?wakka=detected

So if you make llDialog(llDetectedKey(0) ....) in state_entry() nothing will happen. That's the first thing I saw...if I have time to analyze it in detail...i will :).
Myhrrhleine Wingtips
Registered User
Join date: 10 Mar 2008
Posts: 29
06-20-2008 06:37
From: Kahiro Watanabe
It's a common mistake...llDetected... functions works only on:

touch,senor and colission events

http://lslwiki.net/lslwiki/wakka.php?wakka=detected

So if you make llDialog(llDetectedKey(0) ....) in state_entry() nothing will happen. That's the first thing I saw...if I have time to analyze it in detail...i will :).



So since I am using the llDetected to determine who to send the dialog to, I can replace it with llGetOwner since this is intended as a hud item.
Myhrrhleine Wingtips
Registered User
Join date: 10 Mar 2008
Posts: 29
06-21-2008 07:51
From: Kahiro Watanabe
It's a common mistake...llDetected... functions works only on:

touch,senor and colission events

http://lslwiki.net/lslwiki/wakka.php?wakka=detected

So if you make llDialog(llDetectedKey(0) ....) in state_entry() nothing will happen. That's the first thing I saw...if I have time to analyze it in detail...i will :).



Thanks for the help Kahira. I figured out what my problem was. I had my state change in the wrong location. I had it in the sensor, instead of the listen. I switched that and all seems to be well with the world now. Now that I think about it what you said about the llDetected* makes sense, to detect something it requires an outside action , ie touch collision etc. If none of those happen, it can't detect anything because there is nothing to detect.