Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Menu/ touch avatars name

Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
12-09-2007 12:29
having trouble trying to get this to work, when you touch the prim it brings up a dialog box you pick what you wont and it should say (your name) (class) but it dosent seam to wont to show the avatars name that touched it

all it is doing is this

Object: (class)

CODE

key detected;
integer handle;
default
{
state_entry()
{
llSetText("HCS Class Selection",<1,1,1>,1);
}

touch_start(integer total_number)
{

llDialog(llDetectedKey(0), "Class Selection", ["Sniper", "Medic"], -1000);
handle = llListen(-1000, "", llGetObjectName(), "");;
string detected = llKey2Name(llDetectedKey(0));
llListen(-1000, "", llGetObjectName(), "");
}
listen(integer channel, string name, key id, string message)
{
if(message == "Sniper")
{
llListenRemove(handle);
llWhisper(0,(string)detected +" sniper");

}
if(message == "Medic")
{
llListenRemove(handle);
llWhisper(0,(string)detected +" medic");
}
}

}
MCM Villiers
Registered User
Join date: 7 Oct 2007
Posts: 39
12-09-2007 12:32
*sighs* maybe you didnt understand me in world, but heres the fixed code:
key detected;
integer handle;
default
{
state_entry()
{
llSetText("HCS Class Selection",<1,1,1>,1);
}

touch_start(integer total_number)
{

llDialog(llDetectedKey(0), "Class Selection", ["Sniper", "Medic"], -1000);
handle = llListen(-1000, "", llGetObjectName(), "";);;
llListen(-1000, "", llGetObjectName(), "";);
}
listen(integer channel, string name, key id, string message)
{
if(message == "Sniper";)
{
llListenRemove(handle);
llWhisper(0,llKey2Name(id) +" sniper";);

}
if(message == "Medic";)
{
llListenRemove(handle);
llWhisper(0,llKey2Name(id) +" medic";);
}
}

}
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-09-2007 12:37
Yep. You did it again.
Now repeat after me:

"I can not put an event inside an event"
"I can not put an event inside an event"
"I can not put an event inside an event"
"I can not put an event inside an event"
"I can not put an event inside an event"
"I can not put an event inside an event"
"I can not put an event inside an event"
"I can not put an event inside an event"
"I can not put an event inside an event"
"I can not put an event inside an event"
................................
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
12-09-2007 13:33
um. despite previous comments the only thing I can see that is blatantly wrong (and that's not to imply MCM's route isn't better) is that the variable 'detected' is globally declared as a key, and then locally declared, this time as a string, in the touch_start Event Handler. The duplicate llListen might also negate the llListenRemove.

I don't see an event inside an event,

As for the code, in the listen, I'd have gone for:

listen(integer channel, string name, key id, string message)
{
llListenRemove(handle);
llWhisper(0, name + " " + message);
}

:)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-09-2007 13:38
take another look pale, listen is declared in touch_start =)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
12-09-2007 13:48
From: Void Singer
take another look pale, listen is declared in touch_start =)
...at first glance (doing a Quote and copy/paste) it looks that way, but I think it's just perversely formatted. The curly brackets all look good to me.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-09-2007 14:04
well don't I feel silly, sure enough, you're right.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
12-09-2007 14:07
From: Void Singer
take another look pale, listen is declared in touch_start =)
I don't see it either. The script looks fine, except for three errors. I don't think it would compile with the listen event embedded within the touch_start event.

This script above compiles, yet only display a <blank> where the clicker's name should be. The problem is that "detected" was declared as a global "key". "detected" gets set to an avatar's name string only locally within the touch_start event. But "detected" is still nothing outside of that event (the global "detected";).

So three things to fix:
1) change your global detected from a key to a string, and remove the string declaration from:
string detected = llKey2Name(llDetectedKey(0));
2) remove the second: llListen(-1000, "", llGetObjectName(), "";);
3) there's an extra semicolon on your handle-setting line (has no effect on the script).

As for the setting a listen handle for your dialog.. it's good to remove the listen after a successful dialog exchange. However, in your situation, it appears multiple avatars will have access to your device. There is a potential for avatars to "ignore" the dialog, thereby avoiding the llListenRemove() functions of your script. If enough avatars do this, then your script could have too many listens open (and never closed). To avoid that potential, you could remove the old listen before setting the new:

Add llListenRemove(handle); to your touch_start event, above the "handle = ..." line.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-09-2007 14:16
From: Pale Spectre
...at first glance (doing a Quote and copy/paste) it looks that way, but I think it's just perversely formatted. The curly brackets all look good to me.

Yep, My bad. (well actually his. No excuse for formatting like that)Took and pasted all into LSLEditor and hit ctrl D and it comes out like this:
CODE

key detected;
integer handle;
default
{
state_entry()
{
llSetText("HCS Class Selection",<1,1,1>,1);
}

touch_start(integer total_number)
{

llDialog(llDetectedKey(0), "Class Selection", ["Sniper", "Medic"], -1000);
handle = llListen(-1000, "", llGetObjectName(), "");;
string detected = llKey2Name(llDetectedKey(0));
llListen(-1000, "", llGetObjectName(), "");
}
listen(integer channel, string name, key id, string message)
{
if(message == "Sniper")
{
llListenRemove(handle);
llWhisper(0,(string)detected +" sniper");

}
if(message == "Medic")
{
llListenRemove(handle);
llWhisper(0,(string)detected +" medic");
}
}

}

Now that it is properly indented. A few problems pop out at you. Double semi-colon, llListen is duplicated w/o the handle as pointed out by Pale. LLGetObjectName() isn't working in the llListen. Try it with "" instead. You typecast ""detected" globally as a key, which it never is. Typecast globally as a string and remove the typecasts in the events.
CODE

string detected;
integer handle;
default
{
state_entry()
{
llSetText("HCS Class Selection",<1,1,1>,1);
}

touch_start(integer total_number)
{

llDialog(llDetectedKey(0), "Class Selection", ["Sniper", "Medic"], -1000);
handle = llListen(-1000, "", "", "");
detected = llKey2Name(llDetectedKey(0));
}
listen(integer channel, string name, key id, string message)
{
if(message == "Sniper")
{
llWhisper(0,detected +" sniper");
llListenRemove(handle);
}
if(message == "Medic")
{
llWhisper(0,(string)detected +" medic");
llListenRemove(handle);
}
}

}

Works.

Now repeat after me:
I will not make people in the forum suffer with my poor formatting:D
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-09-2007 14:33
The reason llGetObjectName() doesn't work in the llListen is because even though the chat will come from the object's location, it will originate as the name and key of the person who touched it. So if you test it and change to this:
CODE
handle = llListen(-1000, "", "Mrc Homewood", "");

It will work!!!
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
MCM Villiers
Registered User
Join date: 7 Oct 2007
Posts: 39
12-10-2007 03:42
my route was to show him what was wrong not re-write his code :)
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
12-10-2007 03:56
From: MCM Villiers
my route was to show him what was wrong not re-write his code :)

That is fine. We all help as we see fit. But it would be very helpful for a new scripter if it was pointed out to them that they can not use the objects name in the listen from a llDialog and why. None of the problems pointed out in this thread were the root problem and nothing would fix the script until that is corrected. If you try the script that you posted, you will find it does not work.

llDialog is not "spoken" by the object, it is "spoken" by whoever touches it.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum