How do I check a node's type?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Two-Tone

I’m trying to create a simple for-if loop that checks to see if a node is the base node type.

EG

var children_of_bindings = get_node("parent").get_children()
for child in children_of_bindings:
    if child.get_type() == NodeType
        Do_Code   

But I don’t know if there is even class that lets me check what type a node is.

:bust_in_silhouette: Reply From: kidscancode

If you need to check the type of a node you can use is. For example:

if child is Node:

Doesn’t work for what I need. That will happen for every node, which I assume is because every other node is based off it. I just need it to only happen for the base node type.

Two-Tone | 2018-04-06 01:49

What do you mean by “base node type”? That’s what Node is.

kidscancode | 2018-04-06 03:27

Yes, and I’m saying that line returns true for every node, not just a node that is only Node.

EG it returns true for every node in this list, not just the node Node

Two-Tone | 2018-04-06 03:37

I see - I thought you wanted to know if it extended a certain type.

What you want is the node’s class, which you can find with Object.get_class():

if node.get_class() == "Node":

kidscancode | 2018-04-06 03:45

Thank you! That solved my problem!

Two-Tone | 2018-04-06 05:07