Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

int

A built-in type for integers.

Description

Signed 64-bit integer type. This means that it can take values from -2^63 to 2^63 - 1, i.e. from -9223372036854775808 to 9223372036854775807. When it exceeds these bounds, it will wrap around.

ints can be automatically converted to floats when necessary, for example when passing them as arguments in functions. The float will be as close to the original integer as possible.

Likewise, floats can be automatically converted into ints. This will truncate the float, discarding anything after the floating point.

Note: In a boolean context, an int will evaluate to false if it equals 0, and to true otherwise.

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

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

Constructors

int

int ( )

int

int ( int from )

int

int ( String from )

int

int ( bool from )

int

int ( float from )

Operators

bool

operator != ( float right )

bool

operator != ( int right )

int

operator % ( int right )

int

operator & ( int right )

Color

operator * ( Color right )

Quaternion

operator * ( Quaternion right )

Vector2

operator * ( Vector2 right )

Vector2i

operator * ( Vector2i right )

Vector3

operator * ( Vector3 right )

Vector3i

operator * ( Vector3i right )

Vector4

operator * ( Vector4 right )

Vector4i

operator * ( Vector4i right )

float

operator * ( float right )

int

operator * ( int right )

float

operator ** ( float right )

int

operator ** ( int right )

float

operator + ( float right )

int

operator + ( int right )

float

operator - ( float right )

int

operator - ( int right )

float

operator / ( float right )

int

operator / ( int right )

bool

operator < ( float right )

bool

operator < ( int right )

int

operator << ( int right )

bool

operator <= ( float right )

bool

operator <= ( int right )

bool

operator == ( float right )

bool

operator == ( int right )

bool

operator > ( float right )

bool

operator > ( int right )

bool

operator >= ( float right )

bool

operator >= ( int right )

int

operator >> ( int right )

int

operator ^ ( int right )

int

operator unary+ ( )

int

operator unary- ( )

int

operator | ( int right )

int

operator ~ ( )


Constructor Descriptions

int int ( )

Constructs an int set to 0.


int int ( int from )

Constructs an int as a copy of the given int.


int int ( String from )

Constructs a new int from a String, following the same rules as String.to_int.


int int ( bool from )

Constructs a new int from a bool. true is converted to 1 and