0 votes

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?

Godot version 3.2.3 stable official
in Engine by (289 points)
edited by

1 Answer

0 votes

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
by (289 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.