w
wahvay

Never seen this before, whats the purpose?

The part after the parameters of the _init func that shows .(data, actor, targets) . What does it mean by "unique notion to call parents constructor."
  • GDQuestions replied

    In GDScript in Godot 3, you use a .() to call a method on the parent class. You can use that to choose if you want to completely override a method existing on the parent class or extend it. For example:

    var _contents = []
    func add_child(node):
        .add_child(node) # This calls the Node class's add_child() implementation
        _contents.append(node) # But in this script, I want to store extra children in an array named _contents

    In the case of _init(), the class constructor, the notation (or syntax if you prefer) is unique because you have to add the .() inside the function definition, on the first line:

    func _init(data: AttackActionData, actor, targets: Array).(data, actor, targets) -> void:

    This will trigger a call to the parent class's _init() with the arguments data, actor, and targets. Only _init() requires this as far as I know.

    Note I believe this inconsistency is meant to be fixed in Godot 4 with GDScript 2.0.

    3 loves
  • w
    wahvay replied

    Thank you, this makes a ton more sense now