Time for action – Using logical operators
Let's put our first example in code.
var bool bRaining; var float CurrentMoney, RequiredMoney; function PostBeginPlay() { 'log(!bRaining && CurrentMoney > RequiredMoney); } defaultproperties { CurrentMoney=20.0 RequiredMoney=15.0 }
Remembering that bools are false by default, let's take a look at the log:
[0007.94] ScriptLog: True
Even though
bRaining
isFalse
, we're asking the code if it's NOT raining, which isTrue
. You can see why naming booleans is important now. If our variable were calledbNotRaining
, working with logical operators would get messy pretty quickly.Let's look at our second example.
var string Day; function PostBeginPlay() { 'log(Day == "Tuesday" || Day == "Thursday"); } defaultproperties { Day="Monday" }
Since the day variable is neither of those two, we'll get False in the log:
[0007.79] ScriptLog: False
One final operator to discuss is the EXCLUSIVE OR, denoted by two carets (
^^
). This will return...