Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Carcanken |
I’m having some issues trying to program a basic health bar implementation in Godot. This is my first time using signals and after reading through the documentation and stepping through the debugger I’m having a little bit of trouble understanding how exactly the method is not found when my signal is fired.
The error in question is:
emit_signal: Error calling method from signal 'damaged': 'ProgressBar'(ProgressBar.gd)::_onDamageTaken()': Method not found
I have a sprite set up with the following relevant code:
# enemy.gd
extends Sprite
signal damage(by)
signal killed()
func takeDamage(amount):
var prevHealth = health
health -= amount
if prevHealth != health:
emit_signal("damaged", amount)
if health <= 0:
emit_signal("killed")
My ProgressBar implementation is this:
# ProgressBar.gd
extends ProgressBar
onready var character = get_parent()
func _ready():
value = character.maxHealth
character.connect("damaged", self, "_onDamageTaken()")
func _onDamageTaken():
value = character.health
It’s clear that the _onDamageTaken() method is within the script and I can see that it is correctly pulling the proper character node so the issue lies somewhere in the character.connect call.