![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Luzak13 |
I keep getting this error when the signal “no_health” is emitted
E 0:00:06.866 emit_signal: Error calling method from signal ‘no_health’: ‘KinematicBody2D(player.gd)::_no_health’: Method not found…
<C++ Source> core/object.cpp:1242 @ emit_signal()
actor.gd:31 @ _set_health()
actor.gd:57 @ take_damage()
actor.gd:79 @ _start_i_frames()
hurtbox.gd:33 @ _on_Hurtbox_area_entered()
The problem is I already have disconnected the “_no_health” 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 animation_player = $AnimationPlayer
onready var animation_tree = $AnimationTree
onready var hurtbox = $Hurtbox
export var max_health : int = 2 setget _set_max_health, _get_max_health
var health : int = max_health setget _set_health, _get_health
export var maxspeed := 50
export var acceleration := 5
export var friction := 5
var velocity := Vector2.ZERO
var direction := Vector2.ZERO
signal no_health
signal health_changed(new_value)
signal max_health_changed(new_value)
func _ready():
pass
FUNCTIONS
func _set_health(new_value : int)->void:
if new_value <= max_health and new_value >= 0:
health = new_value
if health == 0:
emit_signal(“no_health”)
emit_signal("health_changed", new_value)
func _get_health()->int:
return health
func _set_max_health(new_value : int)->void:
if new_value <= 1:
max_health = 1
elif new_value >= 100:
max_health = 100
else:
max_health = new_value
emit_signal("max_health_changed", max_health)
func _get_max_health()->int:
return max_health
func take_damage(damage : int)->void:
_set_health(_get_health()-damage)
func _init_health(value : int)->void:
_set_max_health(value)
_set_health(value)
func _apply_friction():
velocity = velocity.move_toward(Vector2.ZERO, friction)
func _apply_acceleration():
velocity = velocity.move_toward(direction*maxspeed, acceleration)
func _move():
velocity = move_and_slide(velocity)
func _start_i_frames():
velocity += hurtbox.knockback_source_pos.direction_to(self.global_position)*hurtbox.knockback_received
take_damage(hurtbox.damage_received)
animation_player.play(“start_i_frames”)
func _end_i_frames():
animation_player.play(“end_i_frames”)
player.gd:
extends “res://actors/actor/actor.gd”
export var roll_velocity = 120
var input := Vector2.ZERO
var current_state := 0
var enter_state := true
onready var sword_hitbox = $SlashAxis/SwordHitbox
var tags =
enum { IDLE, WALK, ROLL, ATTACK }
onready var state_machine = animation_tree.get(“parameters/playback”)
func _ready():
hurtbox.invincibility_time = 2
_init_health(1)
func _physics_process(_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 _update_state():
var new_state = current_state
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 _idle_state(_delta):
if enter_state:
state_machine.travel(“Idle”)
enter_state = false
_apply_friction()
func _walk_state(_delta):
_update_blend_position()
if enter_state:
state_machine.travel(“Walk”)
enter_state = false
_apply_acceleration()
func _roll_state(_delta):
if enter_state:
state_machine.travel(“Roll”)
enter_state = false
velocity = direction*roll_velocity
func _attack_state(_delta):
if enter_state:
state_machine.travel(“Attack”)
enter_state = false
_apply_friction()
CHECKERS
func _check_idle_state():
var new_state = current_state
if input != Vector2.ZERO:
new_state = WALK
elif Input.is_action_just_pressed(“ui_cancel”):
new_state = ATTACK
return new_state
func _check_walk_state():
var new_state = current_state
if input == Vector2.ZERO:
new_state = IDLE
elif Input.is_action_just_pressed(“ui_accept”):
new_state = ROLL
elif Input.is_action_just_pressed(“ui_cancel”):
new_state = ATTACK
return new_state
func _check_roll_state():
var new_state = current_state
if “roll_finished” in tags:
new_state = IDLE
remove_tag(“roll_finished”)
return new_state
func _check_attack_state():
var new_state = current_state
if “attack_finished” in tags:
new_state = IDLE
remove_tag(“attack_finished”)
return new_state
func _update_blend_position():
if direction != Vector2.ZERO:
animation_tree.set(“parameters/Walk/blend_position”, direction)
animation_tree.set(“parameters/Idle/blend_position”, direction)
animation_tree.set(“parameters/Roll/blend_position”, direction)
animation_tree.set(“parameters/Attack/blend_position”, direction)
func remove_tag(tag : String):
if tag in tags:
tags.remove(tags.find(tag))
func _end_roll_trigger():
tags.append(“roll_finished”)
func _end_attack_trigger():
tags.append(“attack_finished”)
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…
jgodfrey | 2022-12-12 18:14