Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Listen() handlers in states...

Oracle Omega
MMORPG Pioneer
Join date: 31 Dec 1969
Posts: 61
04-25-2003 14:24
LSL isn't well documented, but the code below is pretty simple.
It doesn't work right (type 'start' to enter moving state, then type 'stop' to return to stopped state.) For some reason the listeners fire alternately, and cummulatively. Are there two bugs here?

b - 1) Are listeners active even when their defining state isn't active?
b - 2) Do listeners accumulate? How would one disable a listener?

CODE

default {
state_entry() {
state stopped;
}
}

state stopped {
state_entry() {
llListen(0,"","","start");
}
listen(integer channel, string name, key id, string message) {
llSay(0,"Starting.");
state moving;
}
}

state moving {
state_entry() {
llListen(0,"","","stop");
}
listen(integer channel, string name, key id, string message) {
llSay(0,"Stopping.");
state stopped;
}
collision(integer colliders) {
llSay(0,"Hit something.");
state stopped;
}
}
Oracle Omega
MMORPG Pioneer
Join date: 31 Dec 1969
Posts: 61
04-25-2003 14:26
OOp. Found one thing:

llListen returns an identifier that can be used to deactivate or remove the listen. [Sorry I missed that.]

I still have the problem with execution scope though. Why would a listen() in an unactive state execute?

Oracle Omega
Phil Metalhead
Game Foundry Leaɗer
Join date: 11 Mar 2003
Posts: 291
04-25-2003 14:44
From: someone
Originally posted by Oracle Omega
I still have the problem with execution scope though. Why would a listen() in an unactive state execute?


afaik, the listen events are state-independent, and thus will remain running until you manually deactivate them. try an llListenRemove() before changing states, that should solve your problem...
Tcoz Bach
Tyrell Victim
Join date: 10 Dec 2002
Posts: 973
04-26-2003 08:35
Only one llListen(0, "", "", "";) required in the default state's state_entry() of you script. It will enable the listen event for all states of your script. Multiple llListens will make your script appear to "hear" once for every time you use it. In your listen event, if (msg == "stop";) { etc. }, if (msg == "start";) { etc. }. If you like to submit the string in advance that's ok but you should still only use llListen() once in the script unless you are listening on more than one channel.
_____________________
** ...you want to do WHAT with that cube? **
Phil Metalhead
Game Foundry Leaɗer
Join date: 11 Mar 2003
Posts: 291
04-26-2003 16:51
actually, i think setting up multiple listens (each triggering on a different keyword) is a good way to do it if you're going to have an object listen only to a few keywords. this way, it doesn't process the listen event at all unless one of the keywords is spoken. of course, you'd still have to have the if (msg == "start";) tests, to separate out the different keywords once the listen event is triggered, but the multiple listens with narrower scopes would be more efficient overall, i think.