Data Types

In previous sections we have covered variables and their scoping rules but little has been said about the different data types that a variable can store. Therefore this chapter 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 GML function, it can also return information. However this information can come in various "flavours", like it can (for example) be a real number or it can be a string. These different types of values being used are called data types and when using GML they can be any of the following:

A string is simply any text that has been placed in quotation marks "...". You can perform certain operations on strings, like add two strings together to create a longer string (concatenation) and you can also change the string properties and even extract real numbers from it. For more information on strings and the string functions see: GameMaker Language Reference - Strings.

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 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 - Real Numbers.

NOTE: On the HTML5 target, all real numbers are doubles.

Note that while created variables in GameMaker Studio 2 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 Studio 2 from an extension and then checked using the appropriate is_*() function, listed at the bottom of this page.

An array is a special data type that can be used to hold multiple values. You assign the array to a variable, and then "fill in" different indices of the array with values. This array can then be passed through to scripts and functions on a pass-by-reference basis, however should you modify the passed array, it will then become a copy of the original array and so will need to be returned back to the original variable for the array to be updated. For more information on arrays, please see: GML Overview - Arrays.

GameMaker Studio 2 will also 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. Note that hexadecimal values can be formatted in either of the following two ways:


For example, the following values can be expressed as hexadecimal as shown:

11406 = $2c8e = 0x2c8e
16777215 = $ffffff = 0xffffff

A boolean is simply a value that can either be true or false. Note that currently GameMaker Studio 2 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:

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#)
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 global scope variables (this is implicit, and they require no "global" prefix) and they have the following structure:

enum <variable>{<constant> [= <value>]}

In the following example, we create an enum for the colours of the rainbow and assign it various constants and default values:

enum rainbowcolors {

The enum entries can only be integer numbers or expressions with previous enums that evaluate to an integer number, and by default are numbered from 0 upwards, so our example given above would default to red = 0, orange = 1, yellow = 2, etc...

You can also assign values to the enum variables at the time of creation:

enum rainbowcolors {
   red = 5,
   orange = 5 * 2,
   yellow = 15,
   green = 20,
   blue = 25,
   indigo = 30,
   violet = 35 * enum_test.entry

Notice in the above example we use another enum to create an expression for "violet". This only works if the enum being referenced was created before the enum that is using it in an expression, but it will not work for variables or functions, since the enum value must be able to be evaluated as a constant on compile. Also note that all enum values evaluate to integer values, and when you create your own you should be aware that only integer values are permitted for enums to work. This value can be any integer number that a floating point double precision number can represent.

To later access the value within a given enum type, you can use the point "." method, like this:

var value =;

Note that you cannot modify the values for any enum constant after it has been created.

An undefined value (also known as a "null" value") is one where an expression doesn't have a correct value, although it is syntactically correct, and so must return something. For example, say you have a ds_map and use the function ds_map_find_value(). Now, what happens when the map does not have the value being looked for? Well, since the function is correctly formatted, and the issue is that the no such value exists, then it would return the constant undefined, and you can check for this constant as you would check for true or any other value.

NaN stands for "not a number", and is a constant that can be returned when the compiler cannot evaluate the results of an operation as a number. For example, 0/0 cannot be defined as a real number, and is therefore represented by NaN, or the square root of a negative number - which is considered an "imaginary" number - cannot be represented as a real number, and so is represented by NaN.

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.

Checking Data Types

GameMaker Studio 2 permits you to check the data type of a given variable using the following functions: