+1 vote

I'm using function connect() to connect a bullet area signal area_entered to the bullet node, once it reaches a certain distance. After that the bullet goes back to the player, enters his area and frees the bullet.
Problem: The bullet instance connects to the player once it reaches certain distance, so it connects a lot of times and I'm getting an error that looks like this:

The function 'connect()' returns a value, but this value is never used.

My connect looks like this:

$"Bullet_Area".connect("area_entered", self, "_on_Bullet_Area_entered")

Why does function connect() return a value "Error"(which is apparently an enum), shouldn't it just return void?
What are you supposed to do with this value, or should I ignore it?

asked Apr 20, 2019 in Engine by Siguantu (13 points)

1 Answer

+4 votes

As shown in the docs for Object.connect(), the return value is an error code. If all goes well, this will be 0 (OK), but it's possible for there to be a failure, in which case you could check the error value to see what's happening. It's potentially useful information, but if everything is working fine, you're ok ignoring it.

The list of errors is here:
https://docs.godotengine.org/en/latest/classes/class_@globalscope.html#enum-globalscope-error

answered Apr 20, 2019 by kidscancode (17,014 points)

Thanks for the response.
According to a reddit post, there is a thing called "discard syntax", that lets you discard a returned value (?)

For anyone having the same it's var _err = connect(...).
If you don't mind, I have another question.
This might be stupid, but if I discard the value, will it still allocate the space in memory for that value?
Like if I have ~200x var _err (in different nodes), will I get a lot of space allocated for no reason?

Well, yes, there's no difference between a variable named err and one named _err. It's just that the warning system will ignore it. You're still allocating memory for an int. Nothing is being "discarded" in this case; you're allocating a local variable that will be freed at the end of the current scope. If you really want to discard the value, do what you're doing now and don't worry about the message.

It's perfectly ok to disregard, disable, or ignore warning messages. If you understand what they mean, you know whether they're a problem or not.

Ha ha ... love error code 48... :D

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.