|
Aleron Wanderer
Joined: 01 Aug 2005 Posts: 76
|
Posted: Wed Oct 04, 2006 2:34 pm
String Comparisons |
I can't seem find any notes addressing this particular problem, so forgive me if it's a common problem. I've simplified the problem into an example trigger.
I have a trigger that matches 'You (*).', and performs the following commands:
Code: |
#SAY %1
#IF (%1 ~= "water") {
#SAY var is water
} {#SAY var is not water} |
When I issue the cough command to my mud, I see the following:
Code: |
You cough loudly.
cough loudly
var is water |
If I change the trigger to match 'You (*) loudly.', the comparison works as it should. So it seems that something is wrong with trying to compare strings with '=' if %1 has a space in it (I'm not sure if this comes up if the string literal on the right has a space in it or not).
Why is this happening? What methods are available to match strings correctly in this kind of a context, where %1 may or may not have spaces in it? I tried using '=~' instead of '=' and again I get the same results. |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Wed Oct 04, 2006 2:39 pm |
Don't use =~ as that pattern matches. (*) can match a number of words and since it does so you should be careful how you go about comparing strings. Use ("%1" = "whatever") instead of (%1 = "whatever").
|
|
_________________ Taz :) |
|
|
|
Aleron Wanderer
Joined: 01 Aug 2005 Posts: 76
|
Posted: Wed Oct 04, 2006 2:45 pm |
That works, thanks. However, I'm still interested in an explanation as to why zMUD seems to be limited to comparing strings without spaces, unless you surround parameter variables with parentheses. According to the expressions help file it does automatic type conversions for the variables/values in an expression after all. Is this unfortunate string comparison implementation implemented the same way in CMud?
|
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Thu Oct 05, 2006 1:18 am |
CMud is completely changing the way %1..%nn are handled, and that is actually the source of the problem in this case. The way zMud handles it is to insert the text represented by the %nn value before it even attempts to parse it. Then the parsing sees "cough loudly = water" which passes to "loudly = water", then "cough 0" which is non-zero and non-null so true. Hence the use of quotes corrects this in zMud.
However in CMud those quotes will actually cause a problem as the %nn references are no longer expanded prior to any parsing. The quotes will be considered and will cause the reference to be treated literally. The references in CMud are properly adjusted so that the quotes are internally built. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Aleron Wanderer
Joined: 01 Aug 2005 Posts: 76
|
Posted: Sat Oct 07, 2006 12:42 pm |
That clears it up nicely. Thank you for the responses. :)
|
|
|
|
|
|