I have this class which is responsable to send me a signal each time my character detect's a parry:
class_name CharacterAttack
signal attack_parried_detected
func _init(body: CharacterBody2D):
character = body
hitbox = body.get_node("HitBox");
hitbox.connect("body_entered", Callable(self, "_on_hit_detected"))
hitbox.connect("body_exited", Callable(self, "_on_body_outs_hitbox"))
self.collisionArea = hitbox.get_node("Area")
#timer
self.timer = Timer.new()
self.timer.one_shot = true
self.timer.wait_time = attack_duration
self.character.add_child(timer)
self.timer.connect("timeout", Callable(self, "_commit_attack"))
func _commit_attack():
for chr in characters_in_attack_area:
if chr.state.current_state != CharacterState.States.PARRYING:
chr.receive_damage.receive(character.attributes.attack_damage)
else:
attack_parried_detected.emit()
characters_in_attack_area.clear()
collisionArea.set_deferred("disabled", true)
character.state.change_state(CharacterState.States.IDLE)
It's a property of my "BaseCharacter" class
# Player.gd
extends CharacterBody2D
class_name BaseCharacter
#core
var state: CharacterState
var animator: CharacterAnimator
var movement: CharacterMovement
var attributes: CharacterAttributes
#att
var _jump_force
var _speed
var _attack_damage
var _health
#Actions
var attack: CharacterAttack
var receive_damage: CharacterReceiveDamage
var die: CharacterDie
var parry: CharacterParry
func _init(jump_force, speed, attack_damage, health):
self._jump_force = jump_force
self._speed = speed
self._attack_damage = attack_damage
self._health = health
func _ready():
#core
state = CharacterState.new(self)
animator = CharacterAnimator.new(self)
attributes = CharacterAttributes.new(self, _speed, _jump_force, _attack_damage, _health)
movement = CharacterMovement.new(self)
#actions
receive_damage = CharacterReceiveDamage.new(self)
attack = CharacterAttack.new(self)
die = CharacterDie.new(self)
parry = CharacterParry.new(self)
self.attack.attack_parried_detected.connect(_handle_parry_attack)
func _handle_parry_attack():
print("ok")
and here I can handle the signal properly... but in my class that extends BaseCharacter class down here, the log "ok1" is never printed, even that in the parent class "ok" is aways printed when a parry is detected
extends BaseCharacter
class_name Player
var jump_force = -250
var speed = 200
var attack_damage = 10
var health = 1000
@onready var camera: Camera2D = $Camera
var playerCameraShaker: PlayerCameraShaker
var self_attack: CharacterAttack
func _init():
super(jump_force, speed, attack_damage, health)
func _handle_parry_attack1():
print("ok 1")
func _ready():
super._ready()
self.attack.attack_parried_detected.connect(_handle_parry_attack1)
self.playerCameraShaker = PlayerCameraShaker.new(self, camera)
func _physics_process(delta: float) -> void:
var direction := Input.get_axis("move_left", "move_right")
movement.add_gravity(delta);
movement.move_x(direction)
if Input.is_action_just_pressed("jump") and self.is_on_floor():
movement.jump(delta)
func _process(delta):
if Input.is_action_just_pressed("attack"):
attack.attack()
if Input.is_action_just_pressed("parry"):
parry.parry()
what am i doing wrong ?
I have this class which is responsable to send me a signal each time my character detect's a parry:
class_name CharacterAttack
signal attack_parried_detected
func _init(body: CharacterBody2D):
character = body
hitbox = body.get_node("HitBox");
hitbox.connect("body_entered", Callable(self, "_on_hit_detected"))
hitbox.connect("body_exited", Callable(self, "_on_body_outs_hitbox"))
self.collisionArea = hitbox.get_node("Area")
#timer
self.timer = Timer.new()
self.timer.one_shot = true
self.timer.wait_time = attack_duration
self.character.add_child(timer)
self.timer.connect("timeout", Callable(self, "_commit_attack"))
func _commit_attack():
for chr in characters_in_attack_area:
if chr.state.current_state != CharacterState.States.PARRYING:
chr.receive_damage.receive(character.attributes.attack_damage)
else:
attack_parried_detected.emit()
characters_in_attack_area.clear()
collisionArea.set_deferred("disabled", true)
character.state.change_state(CharacterState.States.IDLE)
It's a property of my "BaseCharacter" class
# Player.gd
extends CharacterBody2D
class_name BaseCharacter
#core
var state: CharacterState
var animator: CharacterAnimator
var movement: CharacterMovement
var attributes: CharacterAttributes
#att
var _jump_force
var _speed
var _attack_damage
var _health
#Actions
var attack: CharacterAttack
var receive_damage: CharacterReceiveDamage
var die: CharacterDie
var parry: CharacterParry
func _init(jump_force, speed, attack_damage, health):
self._jump_force = jump_force
self._speed = speed
self._attack_damage = attack_damage
self._health = health
func _ready():
#core
state = CharacterState.new(self)
animator = CharacterAnimator.new(self)
attributes = CharacterAttributes.new(self, _speed, _jump_force, _attack_damage, _health)
movement = CharacterMovement.new(self)
#actions
receive_damage = CharacterReceiveDamage.new(self)
attack = CharacterAttack.new(self)
die = CharacterDie.new(self)
parry = CharacterParry.new(self)
self.attack.attack_parried_detected.connect(_handle_parry_attack)
func _handle_parry_attack():
print("ok")
and here I can handle the signal properly... but in my class that extends BaseCharacter class down here, the log "ok1" is never printed, even that in the parent class "ok" is aways printed when a parry is detected
extends BaseCharacter
class_name Player
var jump_force = -250
var speed = 200
var attack_damage = 10
var health = 1000
@onready var camera: Camera2D = $Camera
var playerCameraShaker: PlayerCameraShaker
var self_attack: CharacterAttack
func _init():
super(jump_force, speed, attack_damage, health)
func _handle_parry_attack1():
print("ok 1")
func _ready():
super._ready()
self.attack.attack_parried_detected.connect(_handle_parry_attack1)
self.playerCameraShaker = PlayerCameraShaker.new(self, camera)
func _physics_process(delta: float) -> void:
var direction := Input.get_axis("move_left", "move_right")
movement.add_gravity(delta);
movement.move_x(direction)
if Input.is_action_just_pressed("jump") and self.is_on_floor():
movement.jump(delta)
func _process(delta):
if Input.is_action_just_pressed("attack"):
attack.attack()
if Input.is_action_just_pressed("parry"):
parry.parry()
what am i doing wrong ?
Share Improve this question asked Mar 15 at 11:01 Hiran JúniorHiran Júnior 3653 silver badges11 bronze badges 10 | Show 5 more comments1 Answer
Reset to default 0I've found the problem, it was on my code itself, I was calling "take_damage" into my object which is acctually attacking instead of in one of is elegible to take damage
print(attack.attack_parried_detected.get_connections())
afterSignal.connect()
in both theBaseCharacter
andPlayer
classes. What's the output? (I expect the inheriting class to print one more item than its parent.) – liggiio Commented Mar 15 at 12:48