Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Godot: How to recognize the type of a built-in type?

Tags:

godot

gdscript

In GDScript the is keyword can be used to check whether a value is an instance of a type:

if (input is SomeClass):
    # this works fine

But you can't do that for primitive "built-in" types like strings:

if (input is String):
   # this won't compile 

That gives me a "Parser Error: misplaced expression, misplaced: Built-In Type"

So how do you check if an input is a string?

like image 644
PapaFreud Avatar asked Sep 02 '25 02:09

PapaFreud


1 Answers

Found it!

You can't use is for primitives, but instead there's a typeof function:

if typeof(input) == TYPE_STRING

The value there is a TYPE enum in @GlobalScope.

If your value o is an instance of a class, typeof(o) will return TYPE_OBJECT.

like image 159
PapaFreud Avatar answered Sep 05 '25 02:09

PapaFreud