- Unreal Development Kit Game Programming with UnrealScript:Beginner's Guide
- Rachel Cordone
- 294字
- 2021-08-27 11:59:05
Time for action – Using floats
Floats are used when we need something that doesn't have nice neat values, like how far away something is or how accurate a weapon is. They're declared the same way as our bools and ints, so let's make one now.
- Replace our int declaration with this:
var float DistanceToGo;
- Floats have a default value of 0.0. Let's change our
PostBeginPlay
function to check this.function PostBeginPlay() { 'log("Distance to go:" @ DistanceToGo); }
- Compile and test, and our log should look like this:
[0007.61] ScriptLog: Distance to go: 0.0000
- We can see that unlike ints, floats will log with a decimal place. Let's see if we can change the value. Add this line to the beginning of our
PostBeginPlay
function:DistanceToGo = 0.123;
- Compile and test, and we should see the fraction show up in the log:
[0007.68] ScriptLog: Distance to go: 0.123
- Let's see what happens when we use the same line we did for our int. Change the line to this:
DistanceToGo = 10 / 3;
- Compile and test, and our log should look like this:
[0007.68] ScriptLog: Distance to go: 3.3333
What just happened?
Floats are used when we need precision in our numbers, such as calculating the distance between two points or the time remaining in a game. We also use them for complex math since they can have fractions.
Strings
No, these are not strings for our kittens to play with. In programming, strings store a series of characters, be it letters, numbers, symbols, or a combination of them. We can use them to hold the name of our character, messages to display on the screen, or the name of the weapon we're holding. Let's take a look at how to use them.
推薦閱讀
- 計算機組裝·維護與故障排除
- 精選單片機設計與制作30例(第2版)
- 硬件產品經理成長手記(全彩)
- 3ds Max Speed Modeling for 3D Artists
- 嵌入式系統設計教程
- Artificial Intelligence Business:How you can profit from AI
- R Deep Learning Essentials
- 計算機組裝維修與外設配置(高等職業院校教改示范教材·計算機系列)
- Managing Data and Media in Microsoft Silverlight 4:A mashup of chapters from Packt's bestselling Silverlight books
- 單片機技術及應用
- IP網絡視頻傳輸:技術、標準和應用
- 單片機項目設計教程
- UML精粹:標準對象建模語言簡明指南(第3版)
- Raspberry Pi Home Automation with Arduino
- 電腦主板維修技術