Closed Erawpalassalg closed 4 months ago
I second inheriting constructors by default. I have a base class called ComparisonSort
with a constructor that takes an array. It feels really awful to have to copy and paste
func _init(array).(array):
pass
into each of my seven and growing child classes (BubbleSort
, InsertionSort
, SelectionSort
, etc...), maybe because it adds very un-GDScript-like boilerplate, or it feels like dead code but really isn't.
This is resolved in 4.x, so we can close this?
Closing per @dalexeev's comment.
Describe the project you are working on:
On Godot 3.2.2
Let's say we have a simple project structure with 3 scripts.
Base.gd
which declares a constructor with 1 parameterChild.gd
which inherits fromBase.gd
and do nothingTest.gd
, linked toTest.tscn
, the script to rule them all, which attempts to instantiateChild.gd
on_ready()
Describe the problem or limitation you are having in your project:
First thing first. If I wanted my example to work properly I'd have to do something like
_init(param).(param)
in myChild.gd
. As a side-note, if I wanted to modify my child's constructor, the current state of the editor wouldn't be an issue (except for the compile-time/runtime weirdness, but that's not a big problem)Now, let's say I didn't declare my
Child
's constructor.Base
class, the editor throws a compile-time error sayingToo many arguments for "_init()" call. Expected at most 0.
Invalid call to '_init'. Expected 1 arguments
.This is pretty confusing. But it gets worse.
Let's say, now, that instead of having 3 files, I have only one file declaring 2 inner classes (still called
Base
andChild
). Still not declaring theChild
's constructor.Invalid call to function 'new' in base 'GDScript. Expected 0 argments.
Too few arguments for "_init()" call. Expected at least 1.
None of these error messages are useful in this case. Worse, they muddy the waters about something which is already not that obvious (why do I have to redefine my constructor if I expect my child to be built the same way than its parent? plus this thing has a unique and weird syntax, which is understandable, but already confusing as a beginner).
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
This could be enhanced by either:
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
Unfortunately I have no clue about how to implement this in the Godot's codebase (for now)
If this enhancement will not be used often, can it be worked around with a few lines of script?:
I think it would be used often 😛
Is there a reason why this should be core and not an add-on in the asset library?:
Well, yeah, taht's because it's pretty core stuff