0 votes

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")
in Engine by (26 points)

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 emitsignal: Error calling method from signal 'connected': 'Node2D::onReedSwitchconnected': Method not found..
<C++ Source> core/object.cpp:1228 @ emitsignal()
ReedSwitch.gd:17 @ _on
Area2Dbodyentered()

and:E 0:00:02.202 emitsignal: Error calling method from signal 'connected1': 'Node2D::onReedSwitch2connected1': Method not found..
<C++ Source> core/object.cpp:1228 @ emitsignal()
ReedSwitch2.gd:16 @ _on
ReedSwitch2bodyentered()

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> RETURNVALUEDISCARDED

Level 1.gd:9

1 Answer

0 votes

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.

by (10,894 points)

Here's the connect section.

func _on_Area2D2_connected2():
    isConnected = true

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.

This code, correct?

func _ready():
connect("connected2", self, "Area2D")

I get this:
E 0:00:02.180 emitsignal: Error calling method from signal 'connected2': 'Node2D::onArea2D2connected2': Method not found..
<C++ Source> core/object.cpp:1228 @ emitsignal()
Area2D.gd:22 @ _on
Area2Dbodyentered()

I also get:
E 0:00:02.189 emitsignal: Error calling method from signal 'connected2': 'Area2D(Area2D.gd)::Area2D': Method not found..
<C++ Source> core/object.cpp:1228 @ emit
signal()
Area2D.gd:22 @ onArea2Dbodyentered()

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.

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

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...

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.