- Unreal Development Kit Game Programming with UnrealScript:Beginner's Guide
- Rachel Cordone
- 181字
- 2021-08-27 11:59:09
Time for action – Using if/else
Let's write some code to see if/else in action for ourselves.
- Take the following code:
var int Int1, Int2; function PostBeginPlay() { if(Int1 > Int2) 'log("Int1 is greater than Int2"); else if(Int1 == Int2) 'log("Int1 is equal to Int2"); else 'log("Int1 is less than Int2"); } defaultproperties { Int1=5 Int2=2 }
- What would we expect the result to be? Let's look at the log for the answer:
[0007.72] ScriptLog: Int1 is greater than Int2
What just happened?
We can see that the if
statement is executed and not the else if
or else
statements. Notice that in this example we didn't use the curly brackets in our statements. If there is only one line after the if, else if, or else statements brackets aren't necessary. However, if there are two or more lines, we would need to use brackets.
推薦閱讀
- Raspberry Pi 3 Cookbook for Python Programmers
- 顯卡維修知識精解
- SDL Game Development
- Linux運維之道(第2版)
- The Applied AI and Natural Language Processing Workshop
- Unity 5.x Game Development Blueprints
- 深入淺出SSD:固態存儲核心技術、原理與實戰(第2版)
- 筆記本電腦維修不是事兒(第2版)
- Rapid BeagleBoard Prototyping with MATLAB and Simulink
- 單片機系統設計與開發教程
- 固態存儲:原理、架構與數據安全
- Source SDK Game Development Essentials
- Python Machine Learning Blueprints
- 筆記本電腦芯片級維修從入門到精通(圖解版)
- STM32自學筆記