What is the difference between node type and extends?

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

i add node type of node2d to tree.
and i add this code.

extends Node2D
func _ready():
    pass

when i change code like this

extends CanvasItem
func _ready():
    pass

i can not use Node2D propertie and method by this code.
i can understand about this.

If node2d node can use node2d, is it not necessary to write extends?
is it mean extend itself?
I think nodes are base classes and extends is an extension.

:bust_in_silhouette: Reply From: Kyle Guarco

The reason scripts can be extended fall back to the Godot design principles surrounding Object Oriented Programming. extend defines inheritance, fulfilling that principal.

To answer your question; No, it isn’t implied that the script extends the node from which it’s attached. This is because, while the script automatically inherits from GDScript, they still need an appropriate behavior for the node you’re trying to attach it to.

Scripts also don’t just exist in nodes. As of 3.1, you can create custom classes and create new instances without having to call load() on a script.

I’m sorry I do not understand well
What is the node type for?
If you add node of node2d type, can you use the function of node2d?
Need to expand?

bgegg | 2019-05-10 12:29

As I said above, extend implies inheritance. If you’re inheriting from Node2D, then the “object” you create will inherit from Node2D and all that it inherits from.

Kyle Guarco | 2019-05-11 00:28

thanks ,
understanded it

bgegg | 2019-05-11 10:11