Methods in GDScript
GDScript supports methods defined on custom types. Here’s an example demonstrating this concept:
To run this script, save it as rectangle.gd
and attach it to a Node in your Godot scene. When you run the scene, you should see the following output in the Godot output panel:
In GDScript, all variables are references to objects, similar to how pointers work in some other languages. This means that when you assign an object to a new variable or pass it as an argument, you’re working with a reference to the same object, not a copy.
GDScript doesn’t have the concept of value types vs reference types for method receivers like some other languages do. All method calls in GDScript are effectively on references to objects.
Next, we’ll look at GDScript’s mechanism for defining interfaces, which in Godot are implemented using abstract classes.