You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A collection of games (n/a here, this applies to anything using GDScript).
Describe the problem or limitation you are having in your project
I'm going to preface this with the fact that I'm not sure whether this is a good idea - but would like to get people's thoughts.
It's just occurred to me that I often find myself automatically typing this:
for child in node:# ...
...when I actually mean this:
for child in node.get_children():# ...
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I'm wondering whether it'd be a good idea to make Node an iterator for its children. Because the scene tree is such a fundamental part of developing games with Godot, I suppose this just feels like a natural thing to me.
As a small potential bonus, this wouldn't have to allocate an Array[Node] like get_children() does, as presumably it'd just be using get_child(i) in the iterator.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
As above, iteration over a node's children would be possible by simply doing:
for child in node:# 'child' would also be typed as Node here, ideally.
If this enhancement will not be used often, can it be worked around with a few lines of script?
No, because Node can't be monkey-patched AFAIK.
Is there a reason why this should be core and not an add-on in the asset library?
As above.
The text was updated successfully, but these errors were encountered:
This is not obvious and is not the only possible behavior (for example, you can iterate over the properties). Also, you can already write a custom iterator:
Note that you can provide an additional parameter (include_internal) and also specify a static return type for _iter_get(), GDScript uses it to infer the type of the iterator variable. So this is a full-featured solution.
Describe the project you are working on
A collection of games (n/a here, this applies to anything using GDScript).
Describe the problem or limitation you are having in your project
I'm going to preface this with the fact that I'm not sure whether this is a good idea - but would like to get people's thoughts.
It's just occurred to me that I often find myself automatically typing this:
...when I actually mean this:
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I'm wondering whether it'd be a good idea to make
Node
an iterator for its children. Because the scene tree is such a fundamental part of developing games with Godot, I suppose this just feels like a natural thing to me.As a small potential bonus, this wouldn't have to allocate an
Array[Node]
likeget_children()
does, as presumably it'd just be usingget_child(i)
in the iterator.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
As above, iteration over a node's children would be possible by simply doing:
If this enhancement will not be used often, can it be worked around with a few lines of script?
No, because
Node
can't be monkey-patched AFAIK.Is there a reason why this should be core and not an add-on in the asset library?
As above.
The text was updated successfully, but these errors were encountered: