I got an error and i am trying to make a multiplayer game

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

i’m trying to make a multiplayer game.
I got an error saying.
W 0:00:00.377 The function ‘connect()’ returns a value, but this value is never used.


my code is
func _ready():
get_tree().connect(“network_peer_connected”, self, “_player_conected”)

i’m following a tutorial from Garbaj on how to make a multiplayer game.

:bust_in_silhouette: Reply From: jgodfrey

That’s a Warning rather than an Error. Essentially, the connect() function returns a Error enum (defined here) that tells you whether your call to connect was successful or not.

In the case of your code, your not storing or using that return value and Godot is informing you of that.

To store / use it, you’d do something like this:

var err = get_tree().connect("networkpeerconnected", self, "playerconected")
if err != OK:
   # connection failed - do something

You don’t have to store/use that value - so what you’ve done is perfectly valid. You could do any of:

  • Simply ignore the warning
  • Store / use the return value as above
  • Tell Godot to stop generating that specific warning or that class of warnings