"Too few arguments" for constructor of derived class

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

I have the following GDScript file:

class Base extends Reference:
	
	var a_property
		
	func _init(dict):
		._init()
		a_property = dict.some_property

class Derived extends Base:
	
	var something_more
	
	func _init(dict):
		._init(dict)
		something_more = dict.something

I am aware that this is a bit strange because I don’t define a “main” class, but it actually works as long as I don’t give the Base class constructor any parameters. When I do, like in the above code, then I get an error in line 14 ( at the derived class _init) saying “Too few arguments for _init() call. Expected at least 1.”

I tested the same code splitting it into two scripts “Base.gd” and “Derived.gd” each containing a single main class - the error persists.

Why do I get this weird error message about a missing argument to the constructor?

:bust_in_silhouette: Reply From: archeron

Ah, I figured it out. I was using the wrong syntax to call the parent constructor. It should be:

class Base extends Reference:

    var a_property

    func _init(dict).():

        a_property = dict.some_property

class Derived extends Base:

    var something_more

    func _init(dict).(dict):
        something_more = dict.something

Thank you, thank you, thank you. I don’t know how you find this kind of stuff. Where did you?

FernandoBarahona | 2022-09-06 03:52