Skip to content

11. "NOT" operator by using priorities

sergiodinapoli edited this page Sep 11, 2021 · 1 revision

Suppose you want every pawn - except undergrounders - to say "I love being outside in the sun!".
The first code writing attempt would be of course:
<li>r_logentry(INITIATOR_trait!=undergrounder)->I love being outside in the sun!</li>

Unfortunately, the basic "!=" (i.e. "NOT") operator won't work.
This is because a pawn can have multiple traits. Even if a pawn is "undergrounder", he will typically have other traits too - traits that are obviously not "undergrounder" (no pawn has the same trait twice!). So, even if the pawn has the "undergrounder" trait indeed, the other traits are not "undergrounder" and so the returned result is TRUE (although it had to be FALSE).

So we need an alternative - and here it is:
<li>r_logentry(INITIATOR_trait==undergrounder,priority=1)->I'm not comfortable outdoors.</li>
<li>r_logentry->I love being outside in the sun!</li>

The code checks first if the pawn is an undergrounder. If this is not the case, then it will consider the second line. And since this second line is unconditioned, it will be used always.

So, this snippet does what we wanted: if the pawn is not an undergrounder, the spoken sentence will always be "I love being outside in the sun!". Of course we are forced to create a proper sentence when the pawn is, in fact, an undergrounder. It's a flaw, I admit. If this is a problem, you could use a blank sentence:
<li>r_logentry(INITIATOR_trait==undergrounder,priority=1)-></li>

Not ideal, but it's what we have for now.