-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add a python-like enumerate
option for iterators
#7651
Comments
for i in range(array.size()): Can be shortened to: for i in array.size(): This is also slightly faster in terms of run-time performance. |
I am to assume the proposed implementation (with the Array method) would require it returning tuples, which Godot doesn't have, and I'm not sure it will anytime soon. One other way to go about though, would be to be able to define two variables in the |
Godot can return lists though, and I often return lists of [x.y] :P |
I like the idea in principle, but adding new global scope methods like this technically breaks compatibility. That said, changing the syntax to The bigger problem is that GDScript does not yet support multiple assignment with a line like |
I suppose you are talking about issue #1965 |
#2135 is about array unpacking, which would work as well. |
Describe the project you are working on
irrelevant
Describe the problem or limitation you are having in your project
Especially for
for each
loops it is quite cumbersome to always index the containeror to always add an additional variable:
However an
enumerate
does have numerous additional use cases.Describe the feature / enhancement and how it helps to overcome the problem or limitation
for each
loops with index produce worse readable and/or additional unnecessary code lines, which could be easily avoided.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Just like in python a:
would do the trick.
If this enhancement will not be used often, can it be worked around with a few lines of script?
I think i can confidently assume this would be used a lot.
Is there a reason why this should be core and not an add-on in the asset library?
Needs to be done at core level (to my knowledge it would even require a slight rewrite of "iteration" code base).
The text was updated successfully, but these errors were encountered: