I keep getting this error when the signal "no_health" is emitted
E 0:00:06.866 emitsignal: Error calling method from signal 'nohealth': 'KinematicBody2D(player.gd)::nohealth': Method not found..
<C++ Source> core/object.cpp:1242 @ emitsignal()
actor.gd:31 @ _sethealth()
actor.gd:57 @ takedamage()
actor.gd:79 @ _startiframes()
hurtbox.gd:33 @ _onHurtboxareaentered()
The problem is I already have disconnected the "nohealth" function from this signal in the editor. When I add the function to the "actor.gd" script the errors stop.
actor.gd:
extends KinematicBody2D
onready var animationplayer = $AnimationPlayer
onready var animationtree = $AnimationTree
onready var hurtbox = $Hurtbox
export var maxhealth : int = 2 setget _setmaxhealth, _getmaxhealth
var health : int = maxhealth setget sethealth, gethealth
export var maxspeed := 50
export var acceleration := 5
export var friction := 5
var velocity := Vector2.ZERO
var direction := Vector2.ZERO
signal nohealth
signal healthchanged(newvalue)
signal maxhealthchanged(newvalue)
func _ready():
pass
FUNCTIONS
func sethealth(newvalue : int)->void:
if newvalue <= maxhealth and newvalue >= 0:
health = newvalue
if health == 0:
emitsignal("no_health")
emit_signal("health_changed", new_value)
func gethealth()->int:
return health
func setmaxhealth(newvalue : int)->void:
if newvalue <= 1:
maxhealth = 1
elif newvalue >= 100:
maxhealth = 100
else:
maxhealth = newvalue
emit_signal("max_health_changed", max_health)
func getmaxhealth()->int:
return maxhealth
func takedamage(damage : int)->void:
_sethealth(gethealth()-damage)
func inithealth(value : int)->void:
setmaxhealth(value)
_sethealth(value)
func applyfriction():
velocity = velocity.move_toward(Vector2.ZERO, friction)
func applyacceleration():
velocity = velocity.move_toward(direction*maxspeed, acceleration)
func move():
velocity = moveand_slide(velocity)
func startiframes():
velocity += hurtbox.knockbacksourcepos.directionto(self.globalposition)*hurtbox.knockbackreceived
takedamage(hurtbox.damagereceived)
animationplayer.play("starti_frames")
func endiframes():
animationplayer.play("endiframes")
player.gd:
extends "res://actors/actor/actor.gd"
export var roll_velocity = 120
var input := Vector2.ZERO
var currentstate := 0
var enterstate := true
onready var sword_hitbox = $SlashAxis/SwordHitbox
var tags = []
enum { IDLE, WALK, ROLL, ATTACK }
onready var statemachine = animationtree.get("parameters/playback")
func ready():
hurtbox.invincibilitytime = 2
_init_health(1)
func physicsprocess(_delta):
_move()
func _process(delta):
var x_axis = Input.get_axis("ui_left", "ui_right")
var y_axis = Input.get_axis("ui_up", "ui_down")
input = Vector2(x_axis, y_axis).normalized()
if input != Vector2.ZERO:
direction = input
match current_state:
IDLE:
_idle_state(delta)
WALK:
_walk_state(delta)
ROLL:
_roll_state(delta)
ATTACK:
_attack_state(delta)
_update_state()
func updatestate():
var newstate = currentstate
match current_state:
IDLE:
new_state = _check_idle_state()
WALK:
new_state = _check_walk_state()
ROLL:
new_state = _check_roll_state()
ATTACK:
new_state = _check_attack_state()
if new_state != current_state:
enter_state = true
current_state = new_state
STATES
func idlestate(delta):
if enterstate:
statemachine.travel("Idle")
enterstate = false
applyfriction()
func walkstate(delta):
_updateblendposition()
if enterstate:
statemachine.travel("Walk")
enterstate = false
applyacceleration()
func rollstate(delta):
if enterstate:
statemachine.travel("Roll")
enterstate = false
velocity = direction*roll_velocity
func attackstate(delta):
if enterstate:
statemachine.travel("Attack")
enterstate = false
applyfriction()
CHECKERS
func checkidlestate():
var newstate = currentstate
if input != Vector2.ZERO:
newstate = WALK
elif Input.isactionjustpressed("uicancel"):
newstate = ATTACK
return newstate
func checkwalkstate():
var newstate = currentstate
if input == Vector2.ZERO:
newstate = IDLE
elif Input.isactionjustpressed("uiaccept"):
newstate = ROLL
elif Input.isactionjustpressed("uicancel"):
newstate = ATTACK
return new_state
func checkrollstate():
var newstate = currentstate
if "rollfinished" in tags:
newstate = IDLE
removetag("roll_finished")
return new_state
func checkattackstate():
var newstate = currentstate
if "attackfinished" in tags:
newstate = IDLE
removetag("attackfinished")
return newstate
func updateblendposition():
if direction != Vector2.ZERO:
animationtree.set("parameters/Walk/blendposition", direction)
animationtree.set("parameters/Idle/blendposition", direction)
animationtree.set("parameters/Roll/blendposition", direction)
animationtree.set("parameters/Attack/blend_position", direction)
func remove_tag(tag : String):
if tag in tags:
tags.remove(tags.find(tag))
func endrolltrigger():
tags.append("rollfinished")
func endattacktrigger():
tags.append("attackfinished")