ANSWERED: Why does this connection-checking method return false?

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

I have two nodes, node_a is a Control with a script that tests if a signal is connected from node_b, a Button, when the button is pressed. Here is the code:

func _on_node_b_pressed():
print($node_b.is_connected("pressed", $"..", "on_node_b_pressed()")

It retuns False. Could someone help me?

:bust_in_silhouette: Reply From: exuin

How do I disconnect a signal via code?

Use disconnect() as given here.

But given the description, that doesn’t seem to be what you’re asking. The reason your statement returns False is because your arguments are wrong. $".." gets the parent of the node the script is in, which would be the parent of node_a. Just put self instead. Also, don’t include the parenthesis when passing the method name as an argument (you also forgot the opening underscore). It should look like this instead:

func _on_node_b_pressed():
    print($node_b.is_connected("pressed", self, "_on_node_b_pressed"))

I fixed the question. I’ll try this when I get home, and let you know my success.

ImperialBrake78 | 2020-10-05 17:16

It worked! However the problem in my code was I was freeing the button in another part of the method, which crashes. I fixed the bug and am now able to finish my game. Thanks!

ImperialBrake78 | 2020-10-06 15:47