Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with Sensor and Dialog.. Please

Richard Malaprop
Registered User
Join date: 19 Dec 2005
Posts: 5
01-27-2006 02:36
Ok.. I'm tryig to deteck someone, and send that person a menu.. But I'm getting confused.

Here's the code I have.

sensor(integer total_number)
{
vector pos = llGetPos();
integer j;
integer count = total_number;

for (j = 0; j < count; j++)
{
if(llDetectedName(j) != LOoking_For)
{
float diff = llVecDist(pos,llDetectedPos(j));
integer dist = llRound(diff);
string result = (llDetectedName(j)) + " " + ((string)dist) + "m";

if(llDetectedName(j) != LOoking_For)
{
Looking_For_Key = llDetectedKey(j);
Message = "On";
llMessageLinked(Stub_Button, 0, Message, "";);
}
}
else
{
Message = "Off";

}
llMessageLinked(Stub_Button, 0, Message, "";);
}
}



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

llSensorRepeat(LOoking_For,"",AGENT,200,PI,.5);

Ear = llParseString2List(message, [" "],[]);


list The_COMMANDS = ["Button_1", "Button_2", "Button_3"];
list Temp1;

if The_COMMANDS, [llList2String(Ear, 0)]) != -1) // verify dialog choice
{
llDialog(Looking_For_Key, "What do you want to do?", The_COMMANDS CHANNEL);
...
}
}


Thanks
Kintar Czukor
Registered User
Join date: 23 Jan 2006
Posts: 6
01-27-2006 07:55
Well first of all, the code you've posted isn't even compilable -- too many typos, missing braces and parentheses.

Secondly, it's hard to offer advice if you don't say what the code is doing wrong. ;) You're "getting confused"? Be a little more specific, and I'll see if I can help out.
Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
01-27-2006 08:06
Your code is difficult to follow. Where does the variable "LOoking_For" get set? Also, you create a string called "result" but then never use it.

In your sensor event you have two separate IF statements that both trigger when llDetectedName(j) does not equal LOoking_For. Was one of them supposed to trigger when it DOES equal?
Richard Malaprop
Registered User
Join date: 19 Dec 2005
Posts: 5
Help with Sensor and Dialog
01-27-2006 09:34
Ok.. I clean up the code.

Basically, what I'm trying to acheive, is to detect someone, and show a dialog box to that person only.

Where I am getting confuse, is.. Knowing the person 'Nme', how do I get the key so I can apply to llDialog?

Thanks :)


sensor(integer total_number)
{
vector pos = llGetPos();
integer j;
integer count = total_number;

for (j = 0; j < count; j++)
{
if(llDetectedName(j) != LOoking_For)
{
Message = "Off";
}
else
{
if(llDetectedName(j) == LOoking_For)
{
Looking_For_Key = llDetectedKey(j);
Message = "On";
llMessageLinked(Stub_Button, 0, Message, "";);
}
}
llMessageLinked(Stub_Button, 0, Message, "";);
}
}



listen(integer channel, string name, key id, string message)
{
string LOoking_For = "Helen Moonlight";
key Looking_For_Key;

llSensorRepeat(LOoking_For,"",AGENT,200,PI,.5);


list The_COMMANDS = ["Button_1", "Button_2", "Button_3"];
list Temp1;

if The_COMMANDS, [llList2String(Ear, 0)]) != -1) // verify dialog choice
{
llDialog(Looking_For_Key, "What do you want to do?", The_COMMANDS CHANNEL);
...
}
}
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
01-27-2006 09:53
So you want to have an object that sits there and scans for Helen Moonlight, and when she comes within range, you want it to give her a dialog box? If that's what you want to do, try this:

CODE

string userName = "Helen Moonlight"; // Change this to scan for someone else

key userKey;
integer listenHandle;
integer channel = 40278;

default
{
state_entry()
{
llSensorRepeat(userName, NULL_KEY, AGENT, 96, PI, 10);
}

sensor(integer num)
{
// We found our target, no need to scan any more? Leave this out if
// you want to keep popping up menus and really annoy Helen Moonlight
llSensorRemove();

userKey = llDetectedKey(0);

// Change this to set the actual text on the menu buttons
list menu = ["Button_1", "Button_2", "Button_3"];

llSetTimerEvent(60);
listenHandle = llListen(channel, userName, userKey, "");
llDialog(userKey, "What would you like to do?", menu, channel);
}

timer()
{
llSetTimerEvent(0);
llWhisper(0, "No response received, shutting down.");
llListenRemove(listenHandle);

// Go back to scanning, I guess?
llSensorRepeat(userName, NULL_KEY, AGENT, 96, PI, 10);
}

listen(integer channel, string name, key id, string message)
{
llSetTimerEvent(0);
llListenRemove(listenHandle);

// Change these to match whatever you set on the buttons
if (message == "Button_1")
{
// Do whatever you ned to do if the user clicked Button_1
...
}
else if (message == "Button_2")
{
// Ditto
...
}
else if ... // Repeat for other buttons
{
}
}
}