Two things to keep in mind :
- We do not have any "and" connector (connector being a thing that connects two conditions in this case). We do have an "or" connector, but no "and". That means that we sometimes have to do things in rather strange ways.
- Races checks do not fully work currently. "Positive" race checks correctly check for subraces as far as I know. By "positive" check, I mean a check with "==", as in "race($n) == Dwarf". This condition (race($n) == Dwarf) will be satisfied if $n is a dwarf, or a shield dwarf, or a gold dwarf, or belongs to any subrace of the dwarven race. [As a side note, duergar is NOT coded as a subrace, so we can tell apart the good dwarves and the bad ones. For example, Mithril Hall is restricted to race($n) == Dwarf people ... that explains why duergars are not coded as dwarves.]
Now... since I pointed out that subraces work for "positive" race checks, you might have guessed that they do not work for "negative" race checks. Side note : negative equality [that is, difference] is written !=, not \=. The condition "race($n) != Dwarf" should be satisfied for everybody BUT dwarves, shield dwarves, gold dwarves, and so on. Currently, the code makes it "false" for dwarves, but true for everybody else (including people belonging to dwarven subraces).
That being said ... there's no lesson to learn how to write programs with more complex combinations of conditions. The only piece of advice I can think of is to try and express what you mean by using only "or". Also, note that in most natural languages (i.e., English, French, and so on), the meanings of "or" and "and" are sometimes mixed up (that happens very often in negative sentences), so one needs to be extra careful.
Here, what you mean (if I understood correctly) is :
IF
(race is X) or (race is Y) or (class is Z),
- you cannot enter
ELSE/OTHERWISE
- you can enter
That would "stop some races (X and Y) and classes (Z) from entering, but allow others" in.
An "or" expression is true/satisfied as soon as one of its parts is true. In this case, the bold expression above is true as soon as one of its three parts is true, that is, as soon as $n is of race X, or of race Y, or of class Z. In those cases, $n will be prevented from entering. In all other cases, they can go in.
Turned in code, that yields:
Code: Select all
>intercept_prog north~
if race($n) == Dwarf
or race($n) == Gnome
or class($n) == Rogue
sayto $n I cannot let you in!
else
sayto $n Sure, go in!
mpunintercept
endif
~
Just a last comment to point out the mistake in the prog above, with all the "and" connectors. Let's assume for a minute that we can use "and" in programmes and see what the following programme is going to do.
Code: Select all
!! This is not correct FK code !!
>intercept_prog north~
if race($n) != Dwarf
and race($n) != Gnome
and class($n) != Rogue
sayto $n I cannot let you in!
else
sayto $n Sure, go in!
mpunintercept
endif
~
This programme says that: if the big condition is true, then $n is prevented from entering; otherwise, he can go in. Now, what is the condition ? The condition is (something) and (something) and (something), which is satisfied only when the three "something"s are true, that is ... the condition is satisfied only when
- $n is not a dwarf, and
- $n is not a gnome, and
- $n is not a rogue.
In other words, to be prevented from entering, one needs to be "not a dwarf" and "not a gnome" and "not a rogue" all at once. This is actually the opposite of what you wanted.
A dwarf character, for example, fails to satisfy the condition "not a dwarf". That is the first "something" of the big expression... and since this "something" is false, the whole expression is false. Therefore, the "otherwise/else" part is triggered ... and the dwarf is allowed in.
Actually, the
only way to be prevented from entering is to be a non-dwarf, non-gnome, and non-rogue. So, you are actually keeping out the people you wanted in, and allowing in those you wanted to stay outside.
In a first time, it's better to try and stay completely away from negations in complex conditions. Logic errors in complex conditions involving negations are very common, even in code written by very experienced programmers.
I hope that helps. If you have further questions, please post again!