Replies: 4 comments 9 replies
-
Seems helpful for some custom resources. However I would say the notifications that the array is being changed should probably be handled by the set method instead of get? Since you're changing the value of the array. Also, while I think a feature like this might be nice to include in the engine, you could probably get a lot of these methods by creating a subclass of Array in GDScript and overwriting the relevant methods, where you then emit a signal and call the original method (super). So maybe just having the array signals implemented could be enough and would prevent having to implement this special case for the get/ set methods? |
Beta Was this translation helpful? Give feedback.
-
Seems not:
Result: |
Beta Was this translation helpful? Give feedback.
-
This is an interesting suggestion, but if not implemented carefully it would slow down writing and reading access to the Array considerably, even without making use of the feature. In fact, using ACTION constants and func insert_at_array_index(idx, value)
func remove_at_array_index(idx)
func set_at_array_index(idx, value)
func get_at_array_index(idx) These "middle-men" methods are the way to do this, currently, and that is completely fine. Godot's API already exposes many methods that behave like this. It is probably also expected for the array to not do any special meddling when it is being modified directly. Problem is, there is no way to tell the Editor itself that these methods should be used when modifying the array. As is part of the suggestion, could it be some syntactic sugar exclusive to GDScript? A way to replace the previous methods, such that every access to the array calls them behind the surface. At worst, a special |
Beta Was this translation helpful? Give feedback.
-
I use a helper method with a signature like this: Since that I have moved to typed array versions of it. Sadly, without generic methods, I have to keep a copy of this helper for each type of array I want to have. Thankfully, usually I don't need more than one type per module, which also helps me to not introduce a common dependency between them. I didn't make a proposal for this because I didn't know if this would be well received, I made the mentioned post to try to find out. Yet, it didn't get much attention, probably because brevity eludes me. |
Beta Was this translation helpful? Give feedback.
-
I find myself in this situation (in a custom Resource):
Now there's a nice gui in the Inspector. I add resources to that array, but I need to know as they are:
There's no built-in way, afaict, so I have to resort to playing games with tmp copies and diffing the old and new arrays. It's no fun.
What about something like:
That seems nice. It's not too radical a change and maybe get() can take zero or two params so as not to change code that just uses "get:"
Of course I don't know the underlying deets. Maybe a new keyword like "alter(action, index)"?
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions