-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to use Callables as setters/getters #3316
Comments
What function does
IMO this is already short enough, but we can add the following syntax:
or
Note that an equal sign is used instead of a colon. I think this is more logical and consistent with the rest of the syntax. |
Well, but if we were to introduce new syntax, your proposed one is better. |
This is incorrect code, and it shouldn't work (but of course it shouldn't crash the engine). It should be like this: var my_var:
get: return get_my_var()
set(value): set_my_var(value)
var _my_var
func get_my_var():
return _my_var
func set_my_var(value):
_my_var = value By design, access to Do I understand correctly what you suggest that in the functions |
Looking at it again, my proposal has the same problem as the code that causes infinite recursion .-. So I guess
This has to be true. All these problems are caused by the fact that you can no longer change a property without triggering setter/getter. It's problematic. |
This syntax already exists:
|
🙃 |
Describe the project you are working on
A game using GDScript that I'm going to eventually port to Godot 4.0.
Describe the problem or limitation you are having in your project
There's this new setter syntax:
The problem is that it gets messy with lots of variables with setters, especially if the setters are long.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
We should be able to move the setter/getter body somewhere else. So instead of setter body, we could provide a Callable that gets called as the setter. This would also make auto-converting legacy code much easier.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Or a shorter version:
(although that's reminiscent of the old
setget
, which wasn't very pretty)If this enhancement will not be used often, can it be worked around with a few lines of script?
No. Trying to call a custom method from withing setter/getter body results in infinite recursion and crash without message.
Is there a reason why this should be core and not an add-on in the asset library?
GDScript is core™
The text was updated successfully, but these errors were encountered: