In previous section we covered variables and their scoping rules but little has been said about the different data types that a variable can store. Therefore this section explains the different types and what they can be used for.
Before continuing, let's just briefly explain what we mean by "data types". When you create a variable it can be used to hold information, and when you call a function, it can also stored returned information. However this information can come in various "flavours" - for example, it can be a real number or it can be a string. These different types of values being used are called data types and when using the GameMaker Language they can be any of the following:
Real numbers are any value that is not a string, nor any of the other possible data types. So, 124, 45639.566546456, 0, -45.5 etc... are all examples of real numbers. All real numbers are stored as 64-bit double-precision floating point values (or integer values), and the compiler will optimise where possible (for example, 0.0 will be optimised to the integer value of 0).
When dealing with any value that is not an integer, you may experience slight rounding errors due to the nature of floating point maths. For more information on this and other number related functions, please see: GML Reference - Number Functions.
NOTE On the HTML5 target, all real numbers are doubles.
Note that while created variables in GameMaker are all stored as double-precision floating point numbers or integers, you can still use other formats when dealing with extensions. These can be passed into GameMaker from an extension and then checked using the appropriate is_*() function, a list of which can be found here.
A boolean is simply a value that can either be true or false. Note that currently GameMaker will interpret a real number equal to or below 0.5 as a false value, and any real number greater than 0.5 as being true. This does not mean however that you should be checking 1 and 0 (or any other real number) for true and false, as you are also provided with the constants true and false which should always be used in your code to prevent any issues should real boolean data types be added in a future update.
You can convert any real number into an implicitly boolean value using the following function:
Method VariablesMethod Variables
An "int64" is a 64-bit integer that can be created using int64() (by passing in a non-64-bit real number) or when reading a buffer_u64 value from a buffer.
This can be used in places where a 64-bit integer is strictly required, or when you want to work with bit-shifting and need those 64 bit positions.
Any bitwise operations, even when run on non-64-bit values, will always return a 64-bit integer back.
Divisions on int64 values will also return integers (e.g.: int64(5) / int64(2) = 2).
Hexadecimal ValuesHexadecimal Values
GameMaker will accept hexadecimal literals as legitimate values. Hexadecimal values are especially common when working with colours, but can be used anywhere a positive integer value is required. Hexadecimal values can be formatted in the following two ways, where abcd would be the actual hex value:
$abcd
0xabcd
For example, the following decimal values can be expressed as hexadecimal as shown:
11406 -> $2c8e, 0x2c8e
16777215 -> $ffffff, 0xffffff
A hexadecimal value can also begin with a hash/pound symbol (#), however when written this way, its value will not equal a similar hex value written using a previously shown format ($ or 0x). This is due to the way colours are interpreted in GML, which required the format for hash/pound hex values to be changed so that CSS colours could be written in an #RRGGBB format. For more information, read .
For example, the following two are not equal:
$2c8edd != #2c8edd
For them to refer to the same decimal value, you would have to swap the first two and last two characters:
$2c8edd == #dd8e2c
A pointer is a data type that "points" to a memory location. You cannot do operations on a pointer and it is used only for some very specific functions, like getting a texture or buffer address from memory for another function. For examples of functions that return a pointer you can see buffer_get_address() or sprite_get_texture().
There is also a function to check if a value is a pointer (see "Checking Data Types", below) and a function to convert a value into a pointer:
You may also use (and get returned) the following built in constants when using pointers:
| Constant | Description |
|---|---|
| pointer_null | This constant indicates that the pointer is not pointing to anything meaningful (the same as NULL in C++ or null in C#). This value is falsy. |
| pointer_invalid | This constant simply means that the value is not a valid pointer |
An enum is an "enumerator", and it essentially permits you to create your own limited data type with a list of constant values. Enums are explained in depth on the page for Constants.
Note that since NaN is not a number, it cannot be compared to itself, so comparisons such as NaN == NaN will return false. Same goes for an array comparison such as this:
show_debug_message(array_equals([NaN], [NaN]));
// Output: 0 (false)
The constant infinity refers to a number that is considered infinite, such as the result you would get when dividing any floating point value by zero, eg: 1.0/0.
Note that the infinity constant is equal to itself, so infinity == infinity will return true.
The "Any" data type can be found on many pages in the manual, e.g. in the arguments, or as a return value. It indicates that any type of value is accepted, or can be returned.
You can check the data type of any variable using the functions listed on the following the page:
You can also find arithmetic type tables that show the results of different operations using mixed variable data types here: