...or you could just store the size of the count that way you're not calling a function every single iteration of the loop.
The reason it's not working is because
%i is rising by one while
::getCount() is decreasing by one each time. So say you're clearing 10 bricks:
%b < count
----------
00 < 10
01 < 09
02 < 08
03 < 07
04 < 06
05 < 05It doesn't keep going because %b is no longer less than the count of the group, yet only half the bricks are deleted.
%mainBrickCount = MainBrickGroup.getCount();
for (%i = 0; %i < %mainBrickCount; %i++)
{
%group = MainBrickGroup.getObject(%i);
%groupCount = %group.getCount();
for (%b = 0; %b < %groupCount; %b++)
{
%group.getObject(0).delete();
}
}
Also, you'll want to delete object
0 for the same reason, after half the bricks are deleted %b will be larger than the count of the group, meaning it'll be calling
::delete() on a nonexistant object.
0 will always be an object in the group as long as the group is not empty. You also save the interpreter from having to look up the value of
%b every iteration, which is a
slight performance improvement. In practice, it would probably be negligible, but some people like practicing efficient programming even when the improvement is minor.