Up to date
This page is up to date for Godot
If you still find outdated information, please open an issue.
A built-in type for integers.
Signed 64-bit integer type. This means that it can take values from
2^63 - 1, i.e. from
9223372036854775807. When it exceeds these bounds, it will wrap around.
Note: In a boolean context, an int will evaluate to
false if it equals
0, and to
var x: int = 1 # x is 1 x = 4.2 # x is 4, because 4.2 gets truncated var max_int = 9223372036854775807 # Biggest value an int can store max_int += 1 # max_int is -9223372036854775808, because it wrapped around
int x = 1; // x is 1 x = 4.2; // x is 4, because 4.2 gets truncated // We use long below, because GDScript's int is 64-bit while C#'s int is 32-bit. long maxLong = 9223372036854775807; // Biggest value a long can store maxLong++; // maxLong is now -9223372036854775808, because it wrapped around. // Alternatively with C#'s 32-bit int type, which has a smaller maximum value. int maxInt = 2147483647; // Biggest value an int can store maxInt++; // maxInt is now -2147483648, because it wrapped around
In GDScript, you can use the
0b literal for binary representation, the
0x literal for hexadecimal representation, and the
_ symbol to separate long numbers and improve readability.
var x = 0b1001 # x is 9 var y = 0xF5 # y is 245 var z = 10_000_000 # z is 10000000
int ( )
operator unary+ ( )
operator unary- ( )
operator ~ ( )
int int ( )
Constructs an int set to
Constructs an int as a copy of the given int.
Constructs a new int from a bool.
true is converted to
false is converted to
true if the int is not equivalent to the float.
true if the ints are not equal.
Returns the remainder after dividing two ints. Uses truncated division, which returns a negative number if the dividend is negative. If this is not desired, consider using @GlobalScope.posmod.
print(6 % 2) # Prints 0 print(11 % 4) # Prints 3 print(-5 % 3) # Prints -2
Performs the bitwise
print(0b1100 & 0b1010) # Prints 8 (binary 1000)
This is useful for retrieving binary flags from a variable.
var flags = 0b101 # Check if the first or second bit are enabled. if flags & 0b011: do_stuff() # This line will run.
Multiplies each component of the Color by the int.
Multiplies each component of the Quaternion by the int. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
Multiplies each component of the Vector2 by the int.
print(2 * Vector2(1, 4)) # Prints (2, 8)
Multiplies each component of the Vector2i by the int.
Multiplies each component of the Vector3 by the int.
Multiplies each component of the Vector3i by the int.
Multiplies each component of the Vector4 by the int.
Multiplies each component of the Vector4i by the int.
Multiplies the two ints.
print(2 ** 0.5) # Prints 1.4142135623731
Raises the left int to a power of the right int.
print(3 ** 4) # Prints 81
Adds the int