link to a project file
2)move the bottom sprite to a grid cell (for example, (0, 0) cell)
3)delete the last section "System: For each Sprite4..." and reproduce steps 1 and 2
This last section means "replace all the Sprite4 objects with Sprite3 ones without repeating". The previous section "System: For each Sprite4. Sprite4 is not overlapping Sprite2" deletes every Sprite4 object which is not inside the grid.
So some Sprite4 objects are already deleted but the program obviously places extra Sprite3 objects.
When you destroy a sprite it doesn't actually get destroyed until the next top level event. So in your case it will be destroyed at event 17.
Develop games in your browser. Powerful, performant & highly capable.
do you want to say that it is not a bug and it will never be corrected?
ramones is right - the 'destroy' action actually means 'flag this instance to be destroyed at the end of the next top-level event', because for various reasons the engine cannot truly destroy an object halfway through an event. So the objects will continue to exist and be looped over after a destroy action in a subevent. Does that explain your problem?
A workaround could be to set a 'destroyed' instance variable on the object, and when destroying an instance also set 'destroyed' to true. Then only loop over objects where 'destroyed' is false.
so if it is not a bug then how to replace this code correctly?
Gargo - did you try the workaround I suggested?
Now I ask about it. As I understand it is such a common problem that some common solutions exist, isn't it?
The implementation of Ashley's workaround using a boolean variable.
Closing since this is difficult to fix in the engine and a workaround has been provided.