Crashing With Socket Error 10054 When Sending Argument With emit_signal

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

I’m working my way through the “Godot 3 Complete Developer Course - 2D and 3D” course on Udemy. At the end of the Space Attack section is the assignment to add a health bar for the player. Here is a link to download my full project.
http://www.markalmighty.com/f/ez/downloader.php?d=godot&f=SpaceAttack_by_MarkAlmighty.zip

The game crashes when the player ship gets hit and I’ve included an argument with the emit_signal in Player.gd, Line 63:

func _on_Player_health_changed(new_health):
print(new_health) #<-- WORKS!!!
emit_signal("health_changed", new_health)

The debugger output:
** Debug Process Started **
OpenGL ES 3.0 Renderer: GeForce GTX 1060 6GB/PCIe/SSE2
465.249115
drivers/unix/net_socket_posix.cpp:190 - Socket error: 10054
** Debug Process Stopped **

If I remove the “new_health” argument, there’s no crash. (Of course, the LifeBar also doesn’t get updated.)

:bust_in_silhouette: Reply From: johnygames

I finally found what the problem is!
I downloaded your project and messed around a bit. I noticed that your print(new_health) statement in the func _on_Player_health_changed(new_health) function printed out the same number several times before crashing and I figured that there’s got to be a loop in there somewhere. Then I figured out that you have connected the wrong node to the health_changed signal! You had connected the signal to the Player node, when you should have connected it to the LifeBar node. Go to your Player node, disconnect the signal and reconnect it to LifeBar.
The func _on_Player_health_changed(new_health) will appear in the LifeBar node’s script, where you can place the self.value = new_health logic.

By the way, I noticed that your Player scene has the Player.gd script attached to it, and the Player node in the main scene also has the same script attached to it! Why is that? You do not need to have the same script twice. Also, remember to disconnect the signal both from the Player scene and the Player node in the Main scene.

Please upvote mark this answer as best, so that others can find it useful too!

Thank you for your response, this and the response I got here got me going in the right direction and I was able to complete the task!

MarkAlmighty | 2019-08-07 01:43