Tuesday 13 October 2015

Variables

As talked about by (Gotealeaf, 2015), a Variable is essentially a name or symbol in computer programming that holds and represents a value (like the number 10, or if something's true or false). Value is what Variable is short for, and it can be further changed or altered in software like Unreal 4 to suit the user's needs. In order to follow professional working practices, good-use of naming conventions must be used when using them, ensuring all the names of variables are similar to each other in format (such as having Time_Start and Time_End, keeping the underscore) and allowing the user to quickly type in each variable when programming, without forgetting how it's set out and referring back and forth to each variable name, thus wasting time.
An easy-to-understand diagram showing what a variable is. It's simple purpose is to hold your information and data, and can be easily swapped out at will! (Learn Programming Language Step By Step, 2012)
In Unreal 4 a user normally creates a Variable inside a Blueprint or C++ class, and can then set their data type (talked about below) and then program in their functions using either the Blueprint or C++ scripting languages. Variables in Blueprints are much easier to access and use due to the natural, visual structure it provides. However C++ is much more flexible and capapble when it comes to using Variables, but it has a very intimidating interface with Microsoft's Visual Studio, putting off a lot of beginners and potential users. (Wiki.unrealengine, 2015)

There are a variety of data types for Variables, ranging from Boolean (true or false statements), to Integers (a number). Here's a table below as provided by (cplusplus, 2015) showing all of the data types for C++ and their functions:


GroupType names*Notes on size / precision
Character typescharExactly one byte in size. At least 8 bits.
char16_tNot smaller than char. At least 16 bits.
char32_tNot smaller than char16_t. At least 32 bits.
wchar_tCan represent the largest supported character set.
Integer types (signed)signed charSame size as char. At least 8 bits.
signed short intNot smaller than char. At least 16 bits.
signed intNot smaller than short. At least 16 bits.
signed long intNot smaller than int. At least 32 bits.
signed long long intNot smaller than long. At least 64 bits.
Integer types (unsigned)unsigned char(same size as their signed counterparts)
unsigned short int
unsigned int
unsigned long int
unsigned long long int
Floating-point typesfloat
doublePrecision not less than float
long doublePrecision not less than double
Boolean typebool
Void typevoidno storage
Null pointerdecltype(nullptr)

It means the user should always pick the right Variable type for the job since they all have their uses for different scenarios. For example; if a game wanted the player character to open a door when they move near it, the Boolean Variable in the door for whether or not it's closed should be set to true, but when they move within range of its hitbox the Variable will then change to false, and thus he door will open. This will be until the player has left the range of the hitbox and aren't constantly colliding with it anymore, changing the value to true again and closing the door.

Each type has a specific purpose and aren't really interchangeable, which is why you must use certain ones. If you're counting a score in a game and keeping track of a specific number that's constantly changing as the player progresses, an int datatype is compulsory to use as "The int keyword denotes an integral type that stores values according to the size and range shown in the following table." (Msdn.microsoft a, 2015) So it would be unwise to use a float datatype instead, since they serve a different purpose and the code simply wouldn't work, because: "The float keyword signifies a simple type that stores 32-bit floating-point values. The following table shows the precision and approximate range for the float type". (Msdn.microsoft b, 2015)


No comments:

Post a Comment