Godot: Add a "callback" keyword

Created on 13 Dec 2018  路  9Comments  路  Source: godotengine/godot

Godot version:
11d7738

Issue description:
Add a editor-specific keyword (similar to export or even export) for marking functions as callbacks, so that only callbacks show up when connecting a signal and making a function track in the animation player.
Related to #24316

archived discussion enhancement gdscript

Most helpful comment

no-keyword

All 9 comments

no-keyword

Might be easy to do once #20318 is in place.

More seriously, that's yet another use case that would be better with annotations instead of a keyword.

I don't see how useful this would be. It only makes sense if you have a lot of functions and signals in the same script, at which point you might consider splitting the script into more dedicated libraries. It's also often the case that you have a function to connect to a specific signal so even if it shows up in such list you would only use it once.

I'm also not fond of adding keywords to GDScript just to provide a help in the editor. If this becomes a thing then it should have a practical meaning in the language. For instance, we could make that only callback functions can be connected to signals (and called from the AnimationPlayer as well, maybe). But I don't think this would be helpful.

@vnen I agree with @akien-mga , they should be annotations, that can possibly be kicked out on export.

I disagree with what you said about splitting in different libraries: if you take a look into a call function track interface, even the simplest Node (a bare node) has already 20-30 methods in the list.

But, on the other hand, I am not sure how i would feel if i had to declare a function in my script only to forward a function to the editor. Maybe the functions not marked as export or callback could be folded, so still accessible but not crowding your screen.

functions can already be used like callbacks, i'm confused

Note the wording in the OP:

[...] so that only callbacks show up when connecting a signal and making a function track in the animation player.

The idea is to make an editor-only aid, so as to not get flooded by functions such as set_name or is_visible when viewing the methods of a node.

if you take a look into a call function track interface, even the simplest Node (a bare node) has already 20-30 methods in the list.

Well, they are categorized so the script methods show first. You also might want to call those base functions of the Node, how to choose which ones can be called or not?

I also think that usually you already know the function you want to call so you can just use the search (which is focused by default already).

Besides that, I also fear that is a feature that will confuse users (does the function need to be a callback to be called or it's just an editor hint?) and also just not get known, since most people don't really read the docs.

@vnen I see your point. I'd say then that the problems outweight the gain, so we can close this :)

Was this page helpful?
0 / 5 - 0 ratings