|
Rikeshar Beginner
Joined: 13 Jun 2007 Posts: 11
|
Posted: Sun Jul 29, 2007 4:02 pm
Trigger not compiling |
Hey guys, I need some help. The following trigger is firing, but not compiling. What I'm trying to do is use the #if operator to jerk my fishing line when my @totalbait variable is an even number, and for the trigger to tease my fishing line when the variable is an odd number. Here's what I've got:
#if (@totalbait = *2|*4|*6|*8|*0) {
#class teasing 0
#wa @jerktime
jerk
#class jerking 1
#wa 5000
#class jerking 0} {
#class teasing 1
#wa @teasetime
tease line
#wait 5000
#class teasing 0}
Any ideas why it wouldn't be compiling? |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Jul 29, 2007 5:02 pm |
It is likely confused as to what your trying to do in the expression potion of the #IF. The correct way to do this is actually:
#IF (@totalbait/2=0) {
I would also suggest getting rid of the #WAITs since they have many undesirable effects, even though CMud has improved them into a usable state. Using #ALARMs instead will make the script much more stable. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jul 29, 2007 5:10 pm |
If you click on the Compiled Code tab in the package editor, it'll show you the compiled code for a setting, or the reason why it's not compiling. Also, if you press Ctrl+K while your mouse is inside the Script box of a script with an error, a popup with the error and its location will appear and the cursor will move to the right place.
So, the error, I'm told is "illegal character in expression: * at row 1 col 19" which confirms my suspicions. You're not allowed to use * in an expression like you have at the top. You need to fix your expression, but I'm not sure what you mean it to say. Do you mean if @totalbait is any one of 2, 4, 6, or 8? Or if it's any one of the strings "*2", "*4", "*6", "*8"? Or if it's the string "*2|*4|*6|*8"? To get this to compile, you need to put quotes "" round the value like I have there. You should be doing this for other expressions anyway - (@test=fish) is bad practice. (@test="fish") is better. But even if this had compiled, CMUD would have tried to do the latter and I don't think that's what you want, since you said at the start you wanted to check if it's an even number. There are mathematical ways to find out if a number is even, but I'll just use your way. I think what you probably meant was this:
#if (@totalbait =~ "*{2|4|6|8|0}") {}
=~ is the pattern matching operator - the pattern matches any number of characters (even none) followed by an even number.
EDIT: Argh, ninja'd by Viji :( #wait is still broken in CMUD 1.34, but 2.0 will improve it. It's going to be a while until a public (rather than beta) version of 2.0 is out, though, so it might be worth changing them like he said.
But about your solution...
totalbait=4
#if (@totalbait/2=0) {#say even} {#say odd}
It's an even number, but the #if says it isn't. It detects any number that isn't 2 as odd, apart from 1, which it claims is even. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Jul 29, 2007 5:29 pm |
Ooops. Got the wrong slash in there. It should be a backslash for modulus or the %mod function.
#IF (@totalbait\2=0) {
#IF (%mod(@totalbait,2)=0) { |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jul 29, 2007 5:34 pm |
Can you believe, I'd forgotten all about \ being modulus. That's very confusing, you're right :P
|
|
|
|
|
|