Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

looking for llDetectedName to work when menu button is pushed

Prim Praga
Registered User
Join date: 27 Jul 2008
Posts: 3
09-18-2009 18:27
Hi,
Im a beginner scripter. I am trying to get my script to name the person who pressed the menu button like:
Prim Praga touched me.

However I keep getting an empty null key like 00000000-0000-0000-0000-000000000000

thank you in advance.

Prim

default
{
state_entry()
{
llSetAlpha(0.0,ALL_SIDES);
}
touch_start(integer x)
{


list buttons = ["touched"];

llDialog(

llDetectedKey(0),

"Choose an option",

buttons,

5

);

llListen(5,"","","";);
}

listen(integer chan, string name, key id, string msg)
{

if(msg =="test";)

{

llSay(0, llDetectedName(0) + " touched me.";);


}




}

}
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
09-18-2009 18:34
Those llDetected* functions have very short memories, they only work inside the event where the thing was detected. So, you will want to capture the llDetectedName inside the touch event. Store it in a global string variable if you want to read it back later in that listen.
Ravanne Sullivan
Pole Dancer Extraordinair
Join date: 10 Dec 2005
Posts: 674
09-18-2009 18:36
key curAv;

default
{
state_entry()
{
llSetAlpha(0.0,ALL_SIDES);
}
touch_start(integer x)
{
curAv = llDetectedKey(0);
list buttons = ["touched"];

llDialog(

curAv,

"Choose an option",

buttons,

5

);

llListen(5,"","","";);
}

listen(integer chan, string name, key id, string msg)
{

if(msg =="test";)

{

llSay(0, curAv + " touched me.";);


}




}

}
_____________________
Ravanne's Dance Poles and Animations

Available at my Superstore and Showroom on Insula de Somni
http://slurl.com/secondlife/Insula de Somni/94/194/27/
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
09-18-2009 19:48
Or...

CODE

listen(integer chan, string name, key id, string msg)
{
if(msg =="test")
{
llSay(0, llKey2Name(id) + " touched me.");
.
.

The llKey2Name function doesn't work if the avatar isn't logged in (or on the same region or something like that) but if they just clicked the button, they're probably there..
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-18-2009 19:52
if you're looking for who clicked the button on the menu, it's just the name you get from the listen event

listen(integer channel, string NAME, key id, string message)

you don't need to use key2name for that cause you already have the name
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
09-18-2009 21:13
From: Ruthven Willenov
if you're looking for who clicked the button on the menu, it's just the name you get from the listen event

listen(integer channel, string NAME, key id, string message)

you don't need to use key2name for that cause you already have the name

LOL.. Right. I did know that. Nice catch. :)
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Prim Praga
Registered User
Join date: 27 Jul 2008
Posts: 3
one more question..
09-19-2009 17:58
Just one more question, when I try to add a llDetectedOwner global variable to the button event. I keep getting a type mismatch error.

key name;
key owner;

default
{
touch_start(integer x)
{
name = llDetectedName(0);
owner = llDetectedOwner(0);
list buttons = ["test"];

llDialog(

llDetectedKey(0),

"press a button",

buttons,

5

);

llListen(5,"","","";);
}

listen(integer chan, string name, key id, string msg)
{

if(msg =="test";)

{

llSay(0, name + "hugs" + owner); //I get the type mismatch here, any remedy for this?



}





}



}
Vladimir Petrichor
Registered User
Join date: 6 Apr 2006
Posts: 19
09-19-2009 18:08
I believe your error would be because llDetectedName() returns a string, not a key.


Also, you are probably going to still receive an error because you can only chat strings out...so you need to typecast that key into a string like so...

llSay(0,name + "hugs" + (string)owner);


(Bah...editing this one a bit much because I keep thinking of things to add)

Also, a tip for joining literal strings with variables...those variables (in most cases) aren't going to have spaces padding them...so something like...

llSay(0,name + " hugs " + (string)owner); //note the adding of space around the words hugs

This will make sure your chatted text pops out in a more readable format.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
09-19-2009 18:15
The reason you're getting a type mismatch is that you've cast owner as a key and not a string -- lsl is inconsistent about this, since keys are just special types of string and sometimes it doesn't matter, but if you've explicitly cast something as a key, you can't usually say it. In your code, this will compile but is almost certainly not what you want.

CODE
       llSay(0, name + "hugs" + (string) owner); //will compile -- and will say a key.


I suspect what you want to do is
CODE

// no need to define name up here.. that's done for you in the listen event
string owner;

default
{
state_entry(){
owner = llKey2Name(llGetOwner()); // grab the owner's key and turn it into a name
}



then
CODE
 listen(integer chan, string name, key id, string msg)
{

if(msg =="test")

{

llSay(0, name + " hugs " + owner);

}

}


That should have it saying, "So-and-so hugs Prim Praga", which I imagine is what it's meant to.
Prim Praga
Registered User
Join date: 27 Jul 2008
Posts: 3
09-19-2009 19:24
thank you so much for the help!
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-19-2009 20:33
and you don't really need this:

name = llDetectedName(0);

because you're getting the name from here:

listen(integer chan, string name, key id, string msg)

and i think because you using name in the listen event, it will ignore the global variable anyways
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
09-20-2009 04:45
From: Ruthven Willenov

i think because you using name in the listen event, it will ignore the global variable anyways
I seem to recall, from when I learned this the hard way by once using "id" as the name of a global variable, that it will not so much ignore it but reset the value of "name".
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
09-20-2009 06:41
From: Innula Zenovka
I seem to recall, from when I learned this the hard way by once using "id" as the name of a global variable, that it will not so much ignore it but reset the value of "name".


ah, that makes sense
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
09-20-2009 09:14
From: Innula Zenovka
I seem to recall, from when I learned this the hard way by once using "id" as the name of a global variable, that it will not so much ignore it but reset the value of "name".
I'm not sure what you mean here, but in general, if you redefine, in an inner scope, a variable name that exists in an outer scope, then the two variables are completely independent. Code in the outer scope applies only the outer one; code in the inner scope applies only to the inner one.

E.g.:

CODE

string name = "1";

{
string name = "2";
llSay(0, name);
}

llSay(0, name);


This would print 2 and then 1.

This applies regardless of whether the outer scope is global or not, and regardless of whether the inner definition is a "formal parameter" or is in a block (enclosed in curly braces).

From: sidebar: what's a formal parameter?


A "formal parameter" is when the item being declared is in the parameter list for the definition of a function or event handler, e.g.:

integer foo(string name) { ...

or

listen(integer channel, string name, key id, string msg) { ...
I noticed that the compiler generates an error when a definition hides a definition in a containing scope. This didn't happen earlier, and might only happen for the Mono compiler, or might happen only under certain cases, and it might no longer happen. I only noticed it because when I recompiled some old scripts of mine, I had to change the name of a variable to get it to succeed, even though what I was doing was well-defined.

For LSL (including Mono), I think it's fine if the compiler generates an error in this case. It wouldn't be fine for a language where one writes bigger, more sophisticated programs.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
09-20-2009 10:34
From: Lear Cale
I'm not sure what you mean here, but in general, if you redefine, in an inner scope, a variable name that exists in an outer scope, then the two variables are completely independent. Code in the outer scope applies only the outer one; code in the inner scope applies only to the inner one.

E.g.:

CODE

string name = "1";

{
string name = "2";
llSay(0, name);
}

llSay(0, name);


This would print 2 and then 1.

This applies regardless of whether the outer scope is global or not, and regardless of whether the inner definition is a "formal parameter" or is in a block (enclosed in curly braces).
Yes, I was mistaken. I've just tested it with
CODE
string name;
default
{
state_entry()
{
name = "Anne Avatar";
llListen(2,"", llGetOwner(),"");
}

touch_start(integer total_number)
{
llOwnerSay(name);
}

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

llOwnerSay(name+" said "+message);
}
}
and it says "Ann Avatar" whenever you touch it, and my name when I speak to it.

I do remember I got into all sorts of messes when I foolishly called a global variable "id", though... best avoided, for whatever reason.
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
09-20-2009 10:47
/me nods - a good way to remember it is that the 'nearest' declaration of a variable is the one that it uses.

For example, the following would owner-say "c" then "b" when compiled then "a" when touched..
CODE

string name = "a";

default
{
state_entry()
{
string name = "b";
if (name == "b")
{
string name = "c";

llOwnerSay (name);
}
else
{
llOwnerSay ("call Babbage!!!");
}

llOwnerSay (name);
}

touch_start (integer count)
{
llOwnerSay (name);
}
}
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
09-20-2009 11:06
From: Innula Zenovka


I do remember I got into all sorts of messes when I foolishly called a global variable "id", though... best avoided, for whatever reason.
I doubt there's anything special about the identifier "id". Rather, whenever you have two variables of the same name at different scopes, it's easy to use what you intend to be the outer one, but you get the inner one.

This is why I think it's fine if the compiler objects when you do this, even though it's technically not a "mistake".

So, avoid redefining the same variable name in inner scopes, just for clarity.

On the other hand, I do find it's useful to use the same variable name for the same kind of thing, in different functions and handlers. It makes it easier to cut/paste code to different places.