0 votes

How to do this:

if n is Control:

When you have a string that is the name of the type?

type = "Control" # Comes from somewhere, like an exported var set in editor
if n is type_string:

The latter causes Parser Error: Invalid 'is' test: right operand is not a type (not a native type nor a script).

asked Jul 18, 2019 in Engine by goshot (64 points)
edited Jul 18, 2019 by goshot

1 Answer

0 votes
answered Jul 18, 2019 by kidscancode (17,702 points)

I didn't ask my question very well, so I modified it a bit. My question is how to use a string with "is" instead of a literal type name - perhaps by turning it into a type?

"turning it into a type" doesn't make sense, but I think I see what you are looking for.

GDScript has a method called typeof():

Using this you get a type enum, which is listed here:

So, for example:

if typeof(n) == TYPE_STRING:
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.