Godot integer problem

Godot Version

4.4

Question

`extends Node2D

func _ready() → void:
var tid:int = int(1)
print(typeof(1))

func _process(delta: float) → void:
pass`
in this simple script the output window prints 2 which is TYPE_REAL or float and not integer though the variable being integer. Game is about to launch soon and i am not able to fix this.Please help.

Not sure if this was intentional, but you seem to be doing:

print(typeof(1))

which is imputing a float instead of an int.

I had an issue with this as well at one point since I assumed godot would automatically use int if I did ‘var a = 1’ instead of ‘var a = 1.0’, which it didn’t. Had to write ‘var a : int = 1’ everywhere in my code.

If you want to do an int instead, I think this would work:

print(typeof(int(1)))

or

var tid : int = int(1)
print(tid)

Hopefully this helps

I think you can just do: print(tid)

Which will print what type your variable is i think (your tid variable) and i cant tell if this is gdscript or not but, you can do: var tid: int = 1

Edit: never mind, it only prints the number, not the type of variable it is

1 Like

2 is TYPE_INT

Where are you getting TYPE_REAL? What is the underlying issue you are facing, because I doubt your game is going to fail to launch because typeof(1) == 2

By the way, type_string() exists, that would have cleared the confusion pretty quickly: print(type_string(typeof(1))) # prints "int"

1 Like

Unfortunately this person posted this question twice.
Fortunately it was already resolved.
Unfortunately this thread remains open.

2 Likes

I can’t wait to see the third thread tomorrow

1 Like