|
kjaerhus Magician
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Sun Jul 01, 2007 2:11 pm
Pattern matching problem |
I run through a list of weapon skills and creates trigger to check out if there is any point in using the weapon (preventing pointless overtraining)
Code looks like this:
#VAR weaponMindstates
weaponMindstates = ""
#LOOPDB @weaponSkills {
$weaponKey = %key
$weaponMindStateName = %val
$triggerPattern = "("%db(@weaponSkills, $weaponKey)"):(%s)(%d) (%d)? &%w"$weaponKey
#VAR %exec($weaponKey) ""
#TRIGGER {$triggerPattern} {
#IF (!(@$weaponKey =~ "mind" || @$weaponKey =~ "dazed" || @$weaponKey =~ "bewildered" || @$weaponKey =~ "bewildering")) {
#ADDKEY weaponMindstates $weaponKey @$weaponKey
}
}
}
....
Below is one of the triggers created.
#IF (!(@BRAWL =~ "1" || @BRAWL =~ "1" || @BRAWL =~ "1" || @BRAWL =~ "1")) {
#ADDKEY weaponMindstates BRAWL @BRAWL
}
However I would have expected to compare with the patterns I stated in the code not always against "1". Any ideas about what is wrong? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jul 01, 2007 3:06 pm |
Since your patterns aren't actually patterns, they're strings (they contain no special pattern-matching characters), you don't need the pattern matching operator. Just use a simple equals.
You're also doing some implicit concatenation when you define $triggerPattern that should probably be made explicit using the %concat function. It's hard for me to pick apart what's literal text and what's part of the pattern, so you may need to do that yourself, but it looks like it should be something like this:
$triggerPattern = %concat("(",%db(@weaponSkills,$weaponKey),":(%s)(%d) (%d)? &%w",$weaponKey)
Also, you seem to be using the %exec function for no particular reason there. I think you mean to use %eval - or just brackets with no function should do.
Also, I'm not sure how well that @$weaponkey syntax will work. I think this counts as an implicit concat again before the trigger is created, so you might need to change that as well.
And finally, is there another part of the script that uses the $weaponMindStateName variable? You're not using it at the moment.
I apologise if none of this helps. I don't have access to CMUD at the moment to try out any fixes. |
|
|
|
kjaerhus Magician
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Sun Jul 01, 2007 4:26 pm |
No need to apologise. Any suggestions are welcome, and yours even led me to a working solution.
You say I don't use a pattern but a simple pattern is a pattern too, and there is a slight difference between =~ and == as the first allows characters around it.
Anyway, I solved the problem by using the == operator instead as you suggested. However I think this might be a bug which of course should be fixed. Are you there Zugg? :-) |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Jul 02, 2007 5:34 pm |
Yes, there seems to be a bug with the =~ expressions right now. It's on the bug list.
|
|
|
|
|
|