Topic was automatically imported from the old Question2Answer platform.
Asked By
FSD
Is there a straightforward way to know what a method returns or what a variable is? I end up Googling it for every single thing. Is there a better way? Most IDEs have a go to definition or something equivalent.
You can use typeof() to get an integer from the TYPE enumeration.
int typeof( Variant what )
Returns the internal type of the given Variant object, using the TYPE_* enum in @GlobalScope.
p = parse_json('["a", "b", "c"]')
if typeof(p) == TYPE_ARRAY:
print(p[0]) # prints a
else:
print("unexpected results")
If you’re using GDScript ‘Go to definition’ wouldn’t help for this dynamically-typed language because your variables and functions could hold/return different types. If you needed a method to get the type of a specific variable you could just search in the built in help for ‘type’ and you’d see the typeof() method near the top in the results.
Using the IDE help search, definitions for built-in methods list the return type, eg: