There's something strange about how creating and destroying objects work in relation to functions, and I would really like clarification about what's happening in the examples below.
Obviously in this example, If the layout had no sprites before the trigger, than the sprite count would be 1. Makes perfect sense, but if you count the sprites with a function, something completely different happens
Even though it should be the same sequence of events in the same frame, the text will display 0 this time. And what's really confusing to me, is that this only happens if there are no sprites on the layout at the time of the trigger.
This same concept also seems to apply destroying objects. In this example, the function will count the sprites before they are destroyed instead of after.
One more thing is that if you put Wait 0 in-between the creating/destroying and the function, then everything works as you would expect.
So basically this phenomenon seems to be a very frequent issue in a project I'm working on, (the examples have nothing to do with the project) and I would really like to understand exactly how and why this works so I can work with it better. Specifically, why does this happen in the first place, and why does Wait 0 fix it?