Quick tip: Want to delete elements while iterating over an array? Go backward, start from the last element and work to the front.

If you go forwards, you'll:
❌Skip elements
❌Go out of bounds at the end

Not #GodotEngine specific, but implemented in Godot.
#indiedev #gamedev

@SanderVanhove nice tip! I've never considered this approach. Probably because a lot of languages I've used have functions for filtering arrays anyway. I believe GDScript 2 is also getting a filter feature.

Still a great tip though!

@dopey_kun thanks! Yeah very true! Filters will make it way easier to do something like this. Although sometimes you want to do more than just delete them, so I still see some use in this 😁

@SanderVanhove oh my god thank you so much!! i was just thinking on how to handle this

such nice illustration as well

@SanderVanhove also in vscode there is a quick Action to reverse for loops
@egordorogov no problem, glad I could help out 🤗 Also that is awesome of VSC, it's a great editor!
@SanderVanhove i always create a "zombie" array containing the ids of the element to delete, on wich i loop backwards... your solutin should be more efficient, but it woukd be cool to measure the performance boost
@frankiezafe also a valid solution! I imagine that the performance increase will be very dependent on how many elements are to be removed.
@SanderVanhove your use of visuals to explain these tips is really helpful!
@bronto_games thank you Bronto! I'm going to try to do this more often 🤗