Method not found when I emit signal?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By User457654654

Hello, everyone.
As the name implies, I get an error saying, “Method not found.” This happens when I emit a signal. Here is the part of the code that it is referring to. It’s effectively connected. At the very top right below extends, it says, “signal connected2” Any help would be appreciated! Thank you.

func _on_Area2D_body_entered(body):
	if(body.name == "the_body"):
		$AnimatedSprite.set_frame(1)
		$AnimatedSprite2.set_frame(1)
		emit_signal("connected2")

Oh. I accidentally removed the on. I actually changed up a few of the names. It’s really:

connect("connected1", self, "_on_ReedSwitch2_connected1") 
#and
connect("connected", self, "_on_ReedSwitch_connected")

With…

func _on_ReedSwitch_connected():
	light1 = true


func _on_ReedSwitch2_connected1():
	light2 = true

Still, I still get the errors when the signals are sent: E 0:00:01.969 emit_signal: Error calling method from signal ‘connected’: ‘Node2D::_on_ReedSwitch_connected’: Method not found…
<C++ Source> core/object.cpp:1228 @ emit_signal()
ReedSwitch.gd:17 @ _on_Area2D_body_entered()

and:E 0:00:02.202 emit_signal: Error calling method from signal ‘connected1’: ‘Node2D::_on_ReedSwitch2_connected1’: Method not found…
<C++ Source> core/object.cpp:1228 @ emit_signal()
ReedSwitch2.gd:16 @ _on_ReedSwitch2_body_entered()

I also get errors like this from each one:W 0:00:00.351 The function ‘connect()’ returns a value, but this value is never used.
<C++ Error> RETURN_VALUE_DISCARDED

Level 1.gd:9 [wrap=footnote]User457654654 | 2020-06-13 01:54[/wrap]
:bust_in_silhouette: Reply From: jgodfrey

I don’t think your problem is on the emit side of the signal. It’s likely on the the receive side. So, somewhere you’re receiving the connected2 signal, which will have been defined something like:

connect("connected2", self, "my_function")

Whenever the connected2 signal is received, the above will attempt to call a function named my_function. I’d guess you don’t have that function defined (named whatever you called it in the connect function).

If that doesn’t help, post the connect side of the signal.

Here’s the connect section.

func _on_Area2D2_connected2():
	isConnected = true

User457654654 | 2020-06-12 19:30

But your connected2 signal is a custom signal, right? In that case, somewhere, you should have a statement similar to the one I posted above that actually connects a listener to that signal. Again, that should be something like:

connect("connected2", self, "my_function")

Do you have such code in the script that’s designed to receive the signal?

Also, post the full error so we can see the name of the missing method.

jgodfrey | 2020-06-12 19:38

This code, correct?

func _ready():
connect(“connected2”, self, “Area2D”)

I get this:
E 0:00:02.180 emit_signal: Error calling method from signal ‘connected2’: ‘Node2D::_on_Area2D2_connected2’: Method not found…
<C++ Source> core/object.cpp:1228 @ emit_signal()
Area2D.gd:22 @ _on_Area2D_body_entered()

I also get:
E 0:00:02.189 emit_signal: Error calling method from signal ‘connected2’: ‘Area2D(Area2D.gd)::Area2D’: Method not found…
<C++ Source> core/object.cpp:1228 @ emit_signal()
Area2D.gd:22 @ _on_Area2D_body_entered()

User457654654 | 2020-06-12 20:18

Yes, that’s what I’m looking for. In that connect code you posted, you’re basically telling that script to listen for the connected2 signal, and when it’s received to call a function named Area2D - also found in the current script.

That 2nd error you posted is saying that the script does not have a function named Area2D - which I assume is correct.

That 1st error indicates that a 2nd script is also listening for the connected2 signal, and when it’s received, it’s trying to call a function called onArea2D2connected2 - which also doesn’t exist.

In the original code you posted, it seems like you’re expecting to call _on_Area2D2_connected2 when the signal is received, but that’s not what you defined in the connect code.

Again, according to the errors, it’s looking for a script named Area2D from one place and a script named onArea2D2connected2 in another.

Though, I think the underscores in those function names are causing some rendering trouble here in the forum. Posting the errors inside code tags would fix that…

Bottom line, find your connect("connected2", ... statements (there are at least 2) and see what the 3rd argument to the is. That’s the method that will be called when the signal is received. If that method doesn’t exist (as in your case), you get the errors you reported.

jgodfrey | 2020-06-12 20:41

Darn… Apologies, I’m still new. I think I had a bug in a node so I replaced and fixed it. I am down to one code that has issues now, and each signal has one method not found.

extends Node2D

export var my_bool1 = false
export var my_bool2 = false


func _ready():

	connect("connected1", self, "_on_Area2D2_connected1")
	connect("connected", self, "_on_Area2D1_connected")

# warning-ignore:unused_argument
func _process(delta):
	if(my_bool1 == true and my_bool2 == true):
		$OtherArea2D.hide()


func _on_Area2D1_connected():
	my_bool1 = true


func _Area2D2_connected1():
	my_bool2 = true

User457654654 | 2020-06-13 00:31

So, if that’s your code, you still have a function name mismatch. Notice that you’re trying to connect to a function named _on_Area2D2_connected1 but the actual function name is _Area2D2_connected1.

Note, one has a leading _on and the other doesn’t…

I don’t see a problem with the other function as the names appear to match…

jgodfrey | 2020-06-13 00:50