- Unreal Development Kit Game Programming with UnrealScript:Beginner's Guide
- Rachel Cordone
- 352字
- 2021-08-27 11:59:08
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 true if one and only one of our statements is true. Let's look at the following code:var string Day, Month; function PostBeginPlay() { 'log(Day == "Tuesday" ^^ Month == "January"); } defaultproperties { Day="Tuesday" Month="January" }
If we were using a normal OR, this would return true, but since both of them are true, an EXCLUSIVE OR returns false:
[0007.60] ScriptLog: False
What just happened?
We can see how intertwined logical operators are with normal comparisons. We used the equal and greater than comparisons in our examples. When working with them, the best way to figure out how to write a statement is to say it out loud first and take note of words like AND, NOT, and OR in your sentence. This will help you figure out how to construct a logical operator statement.
- Aftershot Pro:Non-destructive photo editing and management
- 零點(diǎn)起飛學(xué)Xilinx FPG
- Learning AngularJS Animations
- 電腦軟硬件維修大全(實(shí)例精華版)
- 極簡(jiǎn)Spring Cloud實(shí)戰(zhàn)
- 辦公通信設(shè)備維修
- INSTANT Wijmo Widgets How-to
- 嵌入式系統(tǒng)中的模擬電路設(shè)計(jì)
- Machine Learning with Go Quick Start Guide
- 深入理解序列化與反序列化
- 微控制器的應(yīng)用
- USB應(yīng)用開發(fā)寶典
- UML精粹:標(biāo)準(zhǔn)對(duì)象建模語言簡(jiǎn)明指南(第3版)
- 分布式存儲(chǔ)系統(tǒng):核心技術(shù)、系統(tǒng)實(shí)現(xiàn)與Go項(xiàng)目實(shí)戰(zhàn)
- The Machine Learning Workshop