0 votes

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:

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.

in Engine by (30 points)

1 Answer

+1 vote
Best answer

You pass an argument along with the signal "damaged" but the function _onDamageTaken() does not take any arguments. Either get rid of the argument from the signal or add one to the function.

by (7,190 points)
selected by

Removing the argument by changing signal damage(by) to signal damage() and changing emit_signal("damaged", amount) to emit_signal("damaged") does not seem to fix the problem as the same error is still generated.

When you connect the signal, "onDamageTaken ()" is not the same as "onDamageTaken". Remove the parentheses:
character.connect ("damaged", self, "_onDamageTaken")

That got it. Thank you!

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 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 webmaster@godotengine.org with your username.