K

Godot 4 syntax to call parent Constructor in AttackAction.gd

Kikilo

Greetings GDQuest community, I've been taking this course using Godot 4 and identifying the parts where the code should change to have the project 'adapt' to Godot 4. 

One of my findings is relative to this chapter's instructions:

# We must override the constructor to use it.

# Notice how _init() uses a unique notation to call the parent's constructor.

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

    pass


In Godot 4, we should use the following syntax using the super keyword:

func _init(data: AttackActionData, actor, targets: Array):

   super(data, actor, targets) # This calls the same function in the parent class using (data, actor, targets) as the arguments


 

  • Nathan Lovato replied

    This is correct! Thanks for sharing.

    1 love