Object Deletion doesn't seem to work well in a While Loop.
The Attached cap file contains a layout with 1250 Sprites. The code in the Event Sheet is supposed to destroy the Sprites one by one, till only 800 Sprites remain. Here is the code :
System: Start of layout
> Sprite2 : Set 'OBJ' to Sprite 0 .Count
Sprite2 : Value 'OBJ' Greater or equal 800
Sprite: Pick one at random
> Sprite2 : Subtract 1 from 'OBJ'
> Sprite : Destroy
It works and destroys objects as it should.
Yet if you add a While to the seconde line, so the objects could be destroyed in almost no time, in the end there are about 860 sprites, while the "Sprite2"'s variable 'OBJ' has reached 800. Like if sometimes the variable was decremented but no "Sprite" was destroyed. Maybe the final number of Sprites depend on the PC's speed. Mine is pretty slow.
Also, try to replace the "Sprite2 : Subtract 1 from 'OBJ'" by a "Sprite2 : Set 'OBJ' to Sprite.Count", and it goes into an infinite loop. That's weird, because one "Sprite" is supposed to be destroyed at each loop, so the object count should decrease.