Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Trigger on listen event

Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
04-05-2006 15:38
I need some way to trigger an event whenever the object listening hears something. Recently, I've been using "if (message == message)" which doesn't work too well, and has many flaws. How exactly would you set up my request?
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
04-05-2006 15:42
You don't need any check. The listen event fires whenever something is heard, assuming it fits the criteria of the original llListen.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
04-05-2006 15:45
How about:

CODE
if (message == "some specific text that you're looking for")


You want to compare what was said, against some known patterns, right. So on the other side of the == operator, you want the pattern to compare against. For example...

CODE

if (message == "Hello")
{
llSay(0, "Hi, how are you?");
}
else if (message == "Goodbye")
{
llSay(0, "See ya!");
}


I hope that makes sense. You need to compare the variable against something specific, or compare it against another variable. Comparing it with itself will always pass, so that's not a meaningful comparison. It's like checking "if (1 == 1)" ... it will always be true.

I know I'm repeating myself, but I hope I'm able to communicate what I'm trying to say :)
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
04-05-2006 15:50
Well, what I want is something that triggers listening when INSIDE an "if (message == "blahblahblah";)" event. So, lets say:
CODE

default
{
state_entry()
{
llListen(0,"",llGetOwner(),"");
}

listen(integer channel, string name, key id, string message)
{
if (message == "hello")
//Then if someone says anything after I say "hello", then it
//Triggers the event here.
}
}
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
04-05-2006 15:52
From: someone
Then if someone says anything after I say "hello"


Says something after hello... in the same line, like someone saying "hello dolly", or a different person saying something else later, like you saying "hello" and your friend saying "hi"?
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
04-05-2006 15:54
Then you just put
CODE

listen(integer channel, string name, key id, string message)
{
if (message == "hello") {
//code I want to activate when someone says hello
}
}
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
04-05-2006 16:02
I know that, ordinary, it's that I want it to loop. But Ziggy's info earlier fixed the problem; use an else event under the if event. Thanks :D
Sheila Plunkett
On The Prowl!
Join date: 25 Dec 2005
Posts: 67
04-06-2006 06:02
Let's expand this to be a command line interpreter:

CODE

listen(integer channel, string name, key id, string message)
{
list params = llParseString2List(message,[" "],[]);
string cmd = llToLower(llList2String(params,0));
if (cmd == "load") {
//code I want to activate when someone says load
if llListLength(params) < 2 { // 1 Command plus 1 argument
llSay(0,"Useage: load <filename>");
return;
}
string filename = llList2String(params,1);
return;
}
else if (cmd == "save") {
return;
}
else if (cmd == "yawn") {
return;
}
// and so on
}


The advantages:
- The commands are not case sensitive anymore (thanks to llToLower)
- You can easily get the parameters with llList2Whatever (String, Integer, the like) from the list "params", using an idex starting from 1 (as 0 is the command itself)
- You can even easily check for the number of arguments and return an error if neccessary.
- It returns from the function when a valid command is found, saving some runtime.

Feel free to flesh it out as needed.

*meow*
Sheila!