|
Nikoli Karu
Registered User
Join date: 3 Jul 2008
Posts: 7
|
07-03-2008 10:06
I'm having trouble with a script. I'm trying to make a robot that performs a multitude of task, such as: following, calculating, and even lighting up for night time. I want each of these task to be activated by chat commands that are typed in the 5th channel. The problem I'm having is that I want every chat command to be accessible in the default state, but with how the listen event is designed I'm only able to have one chat command for each state.
If anybody knows a work around to this problem please let me know, I'd be very thankful.
|
|
Krista Chaffe
Registered User
Join date: 16 Jun 2007
Posts: 96
|
07-03-2008 10:09
Check the value of the message then use and if (message == "cmd1"  do something else if (message == "cmd2"  do something different .... ....
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
07-03-2008 10:44
I second Krista with an example: default { state_entry() { llListen( 5,"",NULL_KEY,""); } listen(integer kanal, string name, key id, string message) { if (llToLower(message) == "this") { // do this } else if (llToLower(message) == "that") { // do that } else if (llToLower(message) == "cry") { // do cry } // etc. } } Happy scripting 
_____________________
From Studio Dora
|
|
Nikoli Karu
Registered User
Join date: 3 Jul 2008
Posts: 7
|
07-03-2008 12:22
Krista's idea worked. I actually tried exactly that before making this thread, the problem was I forgot two things. I didn't type else before the second if statement, and i only typed one = sign instead of two. Two minor problems that were easily fixed after looking at both of your examples. Thanks for the help. : )
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
07-04-2008 09:15
From: Nikoli Karu I didn't type else before the second if statement That wouldn't prevent the script would working, it'd just make it a bit inefficient by continuing to test for other values once a match had been found. From: someone and i only typed one = sign instead of two. That, however, would be a deal breaker. Just gotta remember, when you're asking "are these two things equal?" use ==. When you're telling it "this is equal to that", use =. One trick experienced coders use (which I myself haven't gotten into the habit of) is, when testing for equality between a variable and a literal value, place the literal first, e.g. if( 5 == x ) That way, if you accidentally type = rather than ==, the compiler will catch it, since you can't assign a value to a literal, only to variables.
|