Topic was automatically imported from the old Question2Answer platform.
Asked By
Godot_Starter
I have a variable var Peter = 0 and then I set this variable to a string or a int and then I want to do something if it is a string and I want to do something if it is an int.
Another solution is to use the is logical operator:
if Peter is String:
print("I'm a string")
elif Peter is int:
print("I'm a integer")
elif Peter is Spatial:
print("I'm a spatial")
elif Peter is Resource:
print("I'm a resource")
and so on.
A good practice is to type your variable, this will avoid type testing and will increase performance of your code: