0 votes

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.
<C++ Error> RETURNVALUEDISCARDED

Lobby.tscn::1:4

my code is
func ready():
get
tree().connect("networkpeerconnected", self, "playerconected")

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

in Engine by (14 points)

1 Answer

0 votes

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
by (10,928 points)
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.