How to determine what type a value is or method returns? (Go to definition?)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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.

:bust_in_silhouette: Reply From: MagicalGirlRosel

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
    print("unexpected results")
:bust_in_silhouette: Reply From: picnic

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:

Node get_node( NodePath path ) const

In online docs linked from the IDE help menu, I found the first two links on this page very useful to compare GDScript with other languages: GDScript — Godot Engine (3.0) documentation in English

Hope that’s some help :smiley:

:bust_in_silhouette: Reply From: metin

Hold CTRL and click on the function.

So simple. So elegant. Somehow I missed it.

FSD | 2018-06-24 14:01

Yes, excellent, thanks metin :smiley:

picnic | 2018-06-24 18:14