Guide to the Godot game engine/Programming/GDScript/Data types

null
Null is the absence of value. Null can be inferred as a function's return value with.

Never evaluates as  in if statements:



This is the default value used in a variable if it has not been set. If a function that you made is supposed to returns something, but instead return, be sure to check the output for errors, and double check the function is working properly.

bool
A bool is a basic data type which may only have 2 values:  (positive, on or 1) and   (negative, off or 0). bool may be inferred as a function's return value with.

bools evaluate as  in an if statements if it is equal to  :



If converted to an integer (with ), it becomes   if it's   and   if.

History
Bools were invented by George Boole. George was an English mathematician whose work is the result of a special programming system. This system may only have 2 values, true and false. It was called "Boolean logic" in his honor.

See the official documentation for more: https://docs.godotengine.org/en/stable/classes/class_bool.html

int
An int, or integer, is a whole number. int may be inferred as a function's return value with.

ints evaluate as  in an if statements if not equal to  :



Operators
Ints are great for maths. They support the following operators:

Comparitive: < Less than > More than == Equal to

Modifiers (use a number on both sides): * Multiplication / Division + Addition - Subtraction % A type of divide. It sets a 64-bit integer to a limit of the second (randi%5 is an integer 0 to 5) ^ To the power of

Useful constants:

Speaking of NaN, NaN is not equal to NaN ( is never true). Instead, use  to see if it is NaN.

To check for infinity (INF is equal to INF, but INF is not equal to -INF), use.

Ints can be separated with underscores, like  (which makes 36234785) to be easier to read.

float
Floats, also known as floating-point numbers, are decimal numbers, like 1.7. float may be inferred as a function's return value with.

floats evaluate as  in an if statements if not equal to  :



Operators
Floats are great for maths. They support the following operators:

Comparative: < Less than > More than == Equal to

Modifiers (use a number on both sides): * Multiplication / Division + Addition - Subtraction

Useful constants:

To check if two numbers are approximately equal (I.e: less than 0.00001 difference), use.

Floats can be separated with underscores to be easier to read, like ints.

String
A versatile data type that can be any length. They are a string of characters. Hence the name "String". String may be inferred as a function's return value with.

Strings evaluate as  in an if statements if not empty:



See the official documentation for more: https://docs.godotengine.org/en/stable/classes/class_string.html

Array
An array is even more versatile than a String. It may be any length, and each value has a numerical index (of int). An Array may be inferred as a function's return value with.

In an if statement Arrays evaluate as  when empty:

[]: []:

Arrays are passed by reference rather than value. See Dictionary.

See the official documentation for more: https://docs.godotengine.org/en/stable/classes/class_array.html]

Dictionary
Dictionarys are the most versatile data type in Godot, besides Objects themselves. Dictionary may be inferred as a function's return value with.

Dictionarys evaluate as  in an if statements if not empty:

{{{Gdscript/string|"team 1"}}:, : }:

Every value is indexed with a value. You can use any data type or Object you wish. As the value or key. FuncRefs and Nodes also count, but remember to keep that same FuncRef or Node (instead of using a different FuncRef for the same function). Even another Dictionary or Array can be used as a key or value.

Dictionaries are passed as reference rather than value, meaning this is never true: {{{Gdscript/string|"red"}}: .red} == {{{Gdscript/string|"red"}}: .red}

Although this is: dictionary={{{Gdscript/string|"red"}}: .red} dictionary == dictionary

This can be useful by saving the same Dictionary in multiple variables, then changing one of them changes them all. If you don't want this functionality, use.

To compare them, use : ({{{Gdscript/string|"red"}}: .red}) == ({{{Gdscript/string|"red"}}: .red})

Indexing
To get a value from a dictionary, you need to retrieve it with its index.

So "Bob" has no points. So the label says "Score: 0".

See the official documentation for more: https://docs.godotengine.org/en/stable/classes/class_dictionary.html

Vector2
A vector is a value with multiple floats. Vector2 is used for 2D positioning among other things. They are indexed at the end with:
 * 1) ".x" or "[0]"
 * 2) ".y" or "[1]"

They are complex things, including many functions. Vector2 may be inferred as a function's return value with.

Vector2s evaluate as  in an if statements if at least one value is not equal to 0:

See the official documentation for more: https://docs.godotengine.org/en/stable/classes/class_vector2.html

Vector3
A vector is a value with multiple floats. A Vector3 has 3 numbers and used for 3D positional and rotational data, among other things. They are indexed at the end with:


 * 1) ".x" or "[0]"
 * 2) ".y" or "[1]"
 * 3) ".z" or "[2]"

Vector3s are complex things, having many functions. Vector3 may be inferred as a function's return value with.

Vector3s evaluate as  in an if statements if at least one value is not equal to 0:

See the official documentation for more: https://docs.godotengine.org/en/stable/classes/class_vector3.html

Color
Technically considered a vector, it contains 4 values:


 * 1) ".r" - the red channel (E.g: 0 is no red, 1 is full red)
 * 2) ".g"- the green channel
 * 3) ".b" - the blue channel
 * 4) ".a" - alpha (or transparency)

Color may be inferred as a function's return value with.

Colors evaluate as  in an "if" statements if not black with no transparency (  is false):

If,   and   are 1, the color is white. If they are 0, the color is black. Know your color wheel! No color or all the colors!

Now, this can be irritating sometimes. How do you quickly get basic colors like orange and yellow? Or common shades of red, green and blue? is a simple way to do so.

All color constants:

See the official documentation for more: https://docs.godotengine.org/en/stable/classes/class_color.html

Basis
A Basis contains a 3x3 matrix for 3D position, rotation and scale of 3D objects. Basis may be inferred as a function's return value with.

Basiss evaluate as  in an if statements if at least one of its Vector3s would also evaluate as true:

Transform2D
A Transform2D is a 2x3 matrix used for 2D linear transformations. It can represent transformations such as translation, rotation or scaling. It consists of three Vector2 values: x, y and origin. Transform2D may be inferred as a function's return value with.

Transform2Ds evaluate as  in an if statements if at least one value is not 0:

See more: The matrices and transforms tutorial.

See the official documentation for more: https://docs.godotengine.org/en/stable/classes/class_transform2d.html

Transform
A Transform is a 3x4 matrix used for 3D linear transformations. It can represent transformations such as translation, rotation or scaling. It consists of a Basis (first 3 Vector3s) and origin (last value). Transform may be inferred as a function's return value with.

Transforms evaluate as  in an if statements if at least one value is not 0:

See more: The matrices and transforms tutorial and the using Transforms tutorial.

See the official documentation for more: https://docs.godotengine.org/en/stable/classes/class_transform.html

Pool Array
For detailed information, please see Array. PoolArrays are optimized versions of Array, but allow storing only one variant type. They also don't contain certain functions, like.

PoolArrays are passed as value rather than reference:

names = ([,, ]) reference_array = [] :   names_copy = names names_copy.append (names, names_copy) reference_array_copy = reference_array reference_array_copy.append (reference_array) copy2 = reference_array. copy2. (reference_array, copy2)

As you can see, the PoolStringArray does not keep the same values across all references, but the Array does.

Allowed types for Pool Arrays are: int, float, string, real (bytes), color, vector2, and vector3. They may only store data types that match the type mentioned in the name, and are more optimized in terms of memory.