Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

More than one listen in a script?

Felix Teriatzi
Registered User
Join date: 8 Jun 2009
Posts: 8
06-14-2009 04:39
I've been working on a script, but I've ran into a problem- I've defined a second listen, but it constantly errors no matter what I do or change. Here's a snippet from the start of the code to the end of the second listen:

---

integer ledstatus;
integer ledmenu;
integer isLight;

string ledparams = "Printing LED Status...";

vector colour;

float intensity;
float glow;

default
{
state_entry()
{
//Listen for '/LEDSTAT'
ledstatus = llListen(0, "", llGetOwner(), "/LEDSTAT";);
//Listen for '/LEDMENU'
ledmenu = llListen(0, "", llGetOwner(), "/LEDMENU";);
llSetTimerEvent(0.0);
//Run when 'LED Status' is said by owner
}
listen( integer channel, string name, key id, string ledstatus )
{
ledparams += "\nColour = "+(string)colour;
ledparams += "\nLight Intensity = "+(string)intensity;
ledparams += "\nGlow Intensity = "+(string)glow;
llOwnerSay(ledparams);
llResetScript();
}
listen( integer channel, string name, key id, string ledmenu )
{
llOwnerSay("Test success!";);
llResetScript();
}

---

When I try to compile it, the script errors at 28, 69 (string ledmenu) with 'Name previously declared within scope'.

I don't have ledmenu defined besides having it an integer and set to be a listen parameter, just like ledstatus. I have no idea what's wrong.

I know it's probably some incredibly simple thing I missed, but please, any help is appreciated.
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
06-14-2009 04:47
It's exactly what it says. It won't let you use the same name, even for different data types. You'll need to change ledmenu in the Listen Event to something else.
Felix Teriatzi
Registered User
Join date: 8 Jun 2009
Posts: 8
06-14-2009 04:59
I don't think I understand what you're saying.

ledmenu is only defined in a listen event once, just like ledstatus. I don't see why ledstatus works and ledmenu doesn't, seeing as they're essentially the same, save for different spelling.
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
06-14-2009 05:06
Variable names can't be used twice in the same scope, no matter of what datatype.

You have "integer ledmenu;" in Global, so you now can't define another variable with the name ledmenu anywhere else in the script, thus why it throws the duplicate error in the Listen event's variable definitions.
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-14-2009 05:21
From: Felix Teriatzi
I've been working on a script, but I've ran into a problem- I've defined a second listen, but it constantly errors no matter what I do or change.
You can not have more than one listen event handler in one state!
When the event occurs what event handler should be used?
Instead: check on you filter values: channel number, speaker key, speaker name and message, in the listen event.
_____________________
From Studio Dora
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
06-14-2009 05:25
Oh wow I didn't even see that, I just saw the first duplicate defined variable, goes to show how helpful I am at 5AM.

Yeah, what you're trying to do would be..

listen( integer channel, string name, key id, string message )
{
if(message == "/LEDSTAT";)
{//ledstat stuff
}
else if(message == "/LEDMENU";)
{//ledmenu stuff
}
}
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
06-14-2009 05:48
Also, every listen has to be checked for every message on a given channel. The ONLY check that is really efficient is the channel check, so not only is there not much (if any) savings for using an llListen string for two separate strings, but you're listening on the wrong channel.

You will lag the sim MUCH less by doing this:

state_entry() { llListen(3, "", llGetOwner(), "";); }

listen(integer channel, string name, key id, string message )
{
if(message == "LEDSTAT";)
{//3ledstat stuff
}
else if(message == "LEDMENU";)
{//3ledmenu stuff
}
}

Now the commands will be "/3LEDSTAT" and "/3LEDMENU".

After a while you'll get tired of having to hit capslock all the time, and you'll change it to:

listen(integer channel, string name, key id, string message )
{
message=llToUpper(message);
if(message == "LEDSTAT";)
{//3ledstat stuff
}
else if(message == "LEDMENU";)
{//3ledmenu stuff
}
}

So /3ledstat and /3ledmenu work as well.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Felix Teriatzi
Registered User
Join date: 8 Jun 2009
Posts: 8
06-14-2009 06:20
Oh, I see the problem.

Thanks a lot, I appreciate it.