i need this to be explained to me like i’m a dumb kid.
why would reading a non-existent key in a structure create it (???)
i understand that you don’t have option or result like they do in rust, but you can at least do the next best thing; returning null, or better yet, throw an error.
don’t tell me it’s “beginner friendly”. it’s not.
you don’t even know that the operation didn’t work, GD just PRETENDS that it works. and now you need 30 mins before even figuring out that you got and error. better yet (or worst yet) you don’t even know that the extra index is caused by a reading error (+30 min for the googling here). and because you now moved on to a new feature, you gotta “search” for the problem (+30 min again). until you can even start fixing it.
if you throw an error, the dev will know right away where the error is (cuz its the last thing added) saving 30 min. plus, you know what caused it (another 30 min saved).
I think its just how engine work
Did you ever wonder why we cannot have animation 0 1 and 2 but skip 3 and 4 and next which we would have is 5?
Nah instead we need it as 0 1 2 3
I guess gdevelop needs some consistency where everything on list is next to other item on list WITHOUT gaps
And now you are kinda in ass when you have for example array with 5 child vars
You delete child vars at index 2 and 3
So now you have 3 child vars
BUT you try to read child at index 4
So you just created child at index 3 again
Why exactly it needs to be this way?
I would assume that is to avoid some issue engine would have trying to read lists with some gaps
And idk if this even should be changed
I would see more sense in looking for a way to better inform user about it
that would be true if you could only pop an index and not delete it. GDevelop is fine having gaps btw. if you change a value at index 5 in array but the array is empty, it will have index 0,1,2,3,4 be null which is gaps (and yes the game continues to run just fine).
(what should happen when you read null? nothing! not… creating the thing you could not read so now you can pretend to read something)
not only that but gaps are a thing in arrays only. structures suffer the same problem of reading a non-existent key, and yet you can’t have gaps. cuz… its keys, not a list.
Yes. It should throw an error either through the diagnostic report or console or maybe even a red screen error. Although, the last might be a bit extreme.
I’ve never liked the idea that just reading an array or structure caused it to be created. While changing that behavior now might be a bit too late, I definitely think that triggering an error could definitely save debugging time.
For newer users: it’s best to check the size of an array before trying to access an index that might not exist. Reminder: indexes start at zero. So, if you’re checking for index 7 then the array would need to have at least 8 indexes.
It might help if there was a condition similar to the child exists for structures. It would be nice to be able to check if say index 7 exists (or is not null) instead of checking if an array had at least 8 items. Checking for the actual index is a little more intuitive.
Until the read behavior is changed, guard each access: check the current array length before using an index, and check that a structure key exists before reading it. During debugging, log the parent variable path and requested index or key just before the access; that usually exposes the first invalid lookup.
yes but checking size of array is still not perfect. as i mentioned above, you can still have null gaps.
also checking child existence of a structure before every fetch is performance heavy.
think about it, why does fetching a child creates it? because the fetching wants to return something. currently, if it doesn’t see it, it creates a key with 0 as value (regardless of default type) so it can return 0. WHY?. if you want to return 0, just return 0, don’t break my structure while your’e at it!!!
of top of that, creating the child steals performance. it makes little sense.