- Unreal Development Kit Game Programming with UnrealScript:Beginner's Guide
- Rachel Cordone
- 370字
- 2021-08-27 11:59:10
Time for action – All classes are created equally
What does this mean for us in practical terms? Let's take a look at our friend AwesomeActor to see if he can help demonstrate.
- Write the following code in our
AwesomeActor
class:class AwesomeActor extends Actor placeable; var() int MyInt; function PostBeginPlay() { `log(self @ MyInt); } defaultproperties { MyInt=4 Begin Object Class=SpriteComponent Name=Sprite Sprite=Texture2D'EditorResources.S_NavP' HiddenGame=True End Object Components.Add(Sprite) }
We'll use an editable
MyInt
variable to see class behavior. - Compile the class and open up the editor. Next to our existing
AwesomeActor
, place another one. - Save the map and run it from the editor, then close out the game and editor.
- Now let's take a look at our
Launch2.log
file:[0010.61] ScriptLog: AwesomeActor_0 4 [0010.61] ScriptLog: AwesomeActor_1 4
We can see that class instances are created with the class name and then a number added to the end. Remembering that in programming everything starts with 0, in our case we have
AwesomeActor_0
andAwesomeActor_1
. Since we haven't changed anything about them yet, both have the default value ofMyInt
, 4. - How do we know which one's which? A handy bar at the bottom of the editor can help us. Reopen the editor and click on one of the AwesomeActors to select it. At the bottom of the editor we can see that instance's name.
- From our log we can see that each instance of
AwesomeActor
has been created in the same manner. Now let's change one of them. Double-click on one to open up its properties, and changeMyInt
to23
. - Save the map and run the game, then exit and take a look at
Launch2.log
.[0007.76] ScriptLog: AwesomeActor_0 4 [0007.76] ScriptLog: AwesomeActor_1 23
What just happened?
We can see that even though both instances were created from the same class blueprint, we can change them after they have been created. This is an important principle of object-oriented programming. Having classes lets us quickly create objects of the same type without having to have a separate file or code for each instance we're going to use. An object is created from the class with all of that class' properties, and then we can change them after they have been created.
- Intel FPGA/CPLD設計(基礎篇)
- Arduino入門基礎教程
- Windows phone 7.5 application development with F#
- 網絡服務器配置與管理(第3版)
- Getting Started with Qt 5
- 平衡掌控者:游戲數值經濟設計
- 深入淺出SSD:固態存儲核心技術、原理與實戰(第2版)
- 計算機組裝與維修技術
- 分布式微服務架構:原理與實戰
- 微軟互聯網信息服務(IIS)最佳實踐 (微軟技術開發者叢書)
- Machine Learning with Go Quick Start Guide
- 筆記本電腦應用技巧
- 基于Proteus仿真的51單片機應用
- STM32自學筆記
- 微控制器的應用