Godot version:
3.1 beta 4
OS/device including version:
Linux 64
Issue description:
Signal callbacks must have the same number of parameters as the arguments passed by the corresponding signal, even if some of them won't be used.
I noticed that using double underscores like this func _input_event(__, event, __, __, __):
supresses the warning, but I'm not sure if it a bug or an undocumented feature, since I couldn't find it in the docs.
I noticed that using double underscores like this
func _input_event(__, event, __, __, __):
supresses the warning
Actually a single underscore should work too, that's indeed the expected behaviour.
I can imagine many users being confused by this warning though. There were already several reports about this.
@vnen Maybe this warning could be made to ignore methods starting with an underscore (typically callbacks with predefined arguments), at least by default. There could be an option (opt-in) to also enable usage checks for arguments of those methods too.
Actually a single underscore should work too, that's indeed the expected behaviour.
Single underscore gives me a "Parser error: Expected identifier for argument"
Ah right, it's single underscore + a name. e.g. func _process(_delta)
.
Is this documented? Is the first time I have seen that (underscore thing).
Maybe the error message can suggest to do it too?
Single underscore should also work, AFAIK one can discard variables in C# that way.
@eon-s The single underscore trick isn't documented here at all. The static typing documentation is also outdated as the GUI pictures displayed no longer exist, and there is no "ignore" shortcut to automatically insert an ignore statement. There isn't even a tooltip or description anywhere detailing what the "key" for the warning is. The warnings panel just displays a description and line number without the unused_variable
or unused_return_value
or what-have-you that you would need to type in a #warning-ignore:
. I have to jump to the ProjectSettings and fish around in the warnings list to identify which rule's name I'm most likely violating. And then I have to memorize those rules (which is ridiculous) so that I don't have to keep looking it up over and over.
@willnationsdev which version are you using? Just tested with master
(a38bf5287) and it does have the warning name and the shortcut to ignore.
Maybe you are mistaking it with the debugger one (which is only shown when you run the project):
About the issue, what's missing is only documentation, as you can already use an underscore prefix to show you're not using the argument.
Maybe the underscore on parameters should be added by default, is not a breaking change and may save some headaches.
Maybe the underscore on parameters should be added by default, is not a breaking change and may save some headaches.
That would defeat the purpose of having checks in the first place.
@akien-mga maybe... but I bet most of the time _process
is utilized without the need to use delta, and signal callbacks (like CollisionObject ones) with few or no parameters used.
User made functions are something else, and the warnings will still work there.
@vnen ahhh, yes. I was confusing it with the debugger one.
Maybe related to #21102
Related to #7599 as well.
What about a GDScript function that would be only used to suppress a warning on a specific argument?
func _process(delta):
unused(delta)
It could be used to suppress warnings on local variables too:
for i in range(0, count):
unused(i)
# do something
This way could be clearer and easier to find in the documentation.
I have seen too that locally unused but globally used variables also get this warning, it needs some kind of macro or something to ignore those kind of variables in an explicit way.
@pouleyKetchoupp underscore is easier to use than an extra line with a dummy function, gdscript may need a better documentation for the specification, also the debugger.
I'd propose adding a help statement to the warning.\
Something like: Consider prefixing with an underscore: _variable_name
That's exactly what the Rust compiler does, for example.
Most helpful comment
Is this documented? Is the first time I have seen that (underscore thing).
Maybe the error message can suggest to do it too?