godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

Add a syntactic sugar for signals, so it becomes very easy to quickly connect and invoke signals #10805

Closed mujtaba-io closed 2 weeks ago

mujtaba-io commented 2 weeks ago

Describe the project you are working on

I am working on many small games that are event driven.

Describe the problem or limitation you are having in your project

I have to use my_signal.connect(my_func)

and i have to emit it using my_signal.emit()

And it is tedious for large amounts of signals.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I think a syntax to recieve a signal could be like this (more convenient):

func foo() listens my_signal:
    pass

and signals are emitted using: emit my_singal

And we dont have to explicitly define signal my_signal as it will be inferred by the names being common in emit/listens statements. Or we can make it appear more like interrupts or exceptions that can be catched or thrown.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

NA

If this enhancement will not be used often, can it be worked around with a few lines of script?

Yes, used often.

Is there a reason why this should be core and not an add-on in the asset library?

Yes, it is related to GDScript.

AThousandShips commented 2 weeks ago

See also:

mujtaba-io commented 2 weeks ago

My above comment might be confusing. So this is the possible syntax that I am thinking about: image

dalexeev commented 2 weeks ago

Of course, these proposals are slightly different, but I think they have a common essence: declarative connection of a signal to a method instead of using connect() or the editor, some shorthand in the form of a keyword or annotation.