Idk what the 'self' does

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

The docs arent explaining very well what this self keyword is, i just want to know what it does. I searched everything and theres nothing saying about it.

:bust_in_silhouette: Reply From: kidscancode

It’s explained in the GDScript basics doc:

self - Refers to current class instance.

It serves essentially the same purpose as self or this in other object-oriented languages.

Specifically in GDScript, when used in a script, it’s a reference to the object the script is attached to.

It’s used whenever you need a reference to the current node, for example when connecting a signal to a local function:

func _ready():
    connect("some_signal", self, "some_function")

func some_function():
    # signal is now connected here