This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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 (297 points)
edited by

1 Answer

+1 vote

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 (297 points)

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

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 Frequently asked questions and 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 [email protected] with your username.