Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.
Contructor override question.old-nightingale```gdscript
# 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
```
I'm still a quite a novice when it comes to programming but I've been able to follow along and understand, mostly. This works in Godot 3, which I also use, but I've also been working through these examples in Godot 4, and I can't get my head around how to make this work.
With my limited knowledge, I'm assuming that we're trying to pass the arguments from the Action class init() to the AttackAction class init(). Assuming I understood this correctly, how would I do this in Godot 4? Do I instantiate the Action class inside AttackAction class?20Jun. 30, 2024
Why apply_async function should be a coroutinexccdsWhy apply_async function should be a coroutine, why not just a normal function? please explain it more, thanks10May. 21, 2024
question about yield(Engine.get_main_loop(), "idle_frame")xccdsthe return of Engine.get_main_loop() should be a MainLoop, MainLoop inherited by SceneTree. SceneTree has a idle_frame signal but MainLoop has not this signal in godot 3.5. so why this line code work? why not use yield(get_tree(), "idle_frame")10May. 21, 2024
Async modifications for Godot 4stupid-grouseThis is how I got it working in godot 4. You have to use bind to pass arguments to a connected signal
```gdscript
func apply_async() -> bool:
# We apply the action to each target so attacks work both for single and multiple targets.
var anim = _actor.battler_anim
for target in _targets:
var status: StatusEffect = StatusEffectBuilder.create_status_effect(target, _data.status_effect)
var hit_chance := Formulas.calculate_hit_chance(_data, _actor, target)
var damage := calculate_potential_damage_for(target)
var hit:= Hit.new(damage, hit_chance, status)
# how we use the triggered signal
anim.triggered.connect(Callable(_on_BattlerAnim_triggered).bind(target, hit))
anim.play("attack")
await _actor.animation_finished
# We're going to define a new function on the battler so it takes hits.
target.take_hit(hit)
await Engine.get_main_loop().idle_frame()
return true
```10May. 05, 2024
Lesson Q&A
Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.