0 votes

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 @ _set
health()
actor.gd:57 @ takedamage()
actor.gd:79 @ _start
iframes()
hurtbox.gd:33 @ _on
Hurtboxareaentered()

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 animation
tree = $AnimationTree
onready var hurtbox = $Hurtbox

export var maxhealth : int = 2 setget _setmaxhealth, _getmaxhealth
var health : int = max
health 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 health
changed(newvalue)
signal max
healthchanged(newvalue)

func _ready():
pass

FUNCTIONS

func sethealth(newvalue : int)->void:
if new
value <= maxhealth and newvalue >= 0:
health = newvalue
if health == 0:
emit
signal("no_health")

emit_signal("health_changed", new_value)

func gethealth()->int:
return health

func setmaxhealth(newvalue : int)->void:
if newvalue <= 1:
max
health = 1
elif newvalue >= 100:
max
health = 100
else:
maxhealth = newvalue

emit_signal("max_health_changed", max_health)

func getmaxhealth()->int:
return max
health

func takedamage(damage : int)->void:
_set
health(gethealth()-damage)

func inithealth(value : int)->void:
setmaxhealth(value)
_set
health(value)

func applyfriction():
velocity = velocity.move_toward(Vector2.ZERO, friction)

func applyacceleration():
velocity = velocity.move_toward(direction*maxspeed, acceleration)

func move():
velocity = move
and_slide(velocity)

func startiframes():
velocity += hurtbox.knockback
sourcepos.directionto(self.globalposition)*hurtbox.knockbackreceived
takedamage(hurtbox.damagereceived)
animationplayer.play("starti_frames")

func endiframes():
animation
player.play("endiframes")

player.gd:

extends "res://actors/actor/actor.gd"

export var roll_velocity = 120

var input := Vector2.ZERO
var currentstate := 0
var enter
state := true

onready var sword_hitbox = $SlashAxis/SwordHitbox

var tags = []

enum { IDLE, WALK, ROLL, ATTACK }

onready var statemachine = animationtree.get("parameters/playback")

func ready():
hurtbox.invincibility
time = 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 enter
state:
statemachine.travel("Idle")
enter
state = false
applyfriction()

func walkstate(delta):
_update
blendposition()
if enter
state:
statemachine.travel("Walk")
enter
state = false
applyacceleration()

func rollstate(delta):
if enter
state:
statemachine.travel("Roll")
enter
state = false

velocity = direction*roll_velocity

func attackstate(delta):
if enter
state:
statemachine.travel("Attack")
enter
state = false
applyfriction()

CHECKERS

func checkidlestate():
var new
state = currentstate
if input != Vector2.ZERO:
new
state = WALK
elif Input.isactionjustpressed("uicancel"):
newstate = ATTACK
return new
state

func checkwalkstate():
var new
state = currentstate
if input == Vector2.ZERO:
new
state = IDLE
elif Input.isactionjustpressed("uiaccept"):
newstate = ROLL
elif Input.is
actionjustpressed("uicancel"):
new
state = ATTACK
return new_state

func checkrollstate():
var new
state = currentstate
if "roll
finished" in tags:
newstate = IDLE
remove
tag("roll_finished")

return new_state

func checkattackstate():
var new
state = currentstate
if "attack
finished" in tags:
newstate = IDLE
remove
tag("attackfinished")
return new
state

func updateblendposition():
if direction != Vector2.ZERO:
animation
tree.set("parameters/Walk/blendposition", direction)
animation
tree.set("parameters/Idle/blendposition", direction)
animation
tree.set("parameters/Roll/blendposition", direction)
animation
tree.set("parameters/Attack/blend_position", direction)

func remove_tag(tag : String):
if tag in tags:

    tags.remove(tags.find(tag))

func endrolltrigger():
tags.append("roll
finished")

func endattacktrigger():
tags.append("attack
finished")

Godot version 3.5.1
in Engine by (12 points)

That's way too much UNFORMATTED code to look through on the forum. Formatting it would make it much easier to read here.

However, it sounds like your no_health() function is still being called when you don't think it should be. First, I'm confident that it is being legitimately called somewhere in your project - you just need to find out where.

If you can't find it by looking through the editor, you can always search your scene files for that function name. Either via some OS-specific form of grep or simply by opening each tscn file in a text editor and searching manually.

I'm sure there is a reference in there somewhere that you've lost track of...

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.