Godot - Check if variable is number
GDScript code example to check if variable is number using typeof()
.
Can check if variable type is number using typeof()
in GDScript.
Check if return value of typeof()
matches "TYPE_INT".
var value = 10
if typeof(value) == TYPE_INT:
print("It's a number")
else:
push_error("Not a number")
To check if a variable is of type float using typeof()
, you would check if it matches "TYPE_REAL".
var value = 1.5
if typeof(value) == TYPE_REAL:
print("It's a number")
else:
push_error("Not a number")