%mct = MainBrickGroup.getCount();
for(%i = 0; %i < %mct; %i++)
{
%obj = MainBrickGroup.getObject(%i);
if(!%oct = %obj.getCount())
continue;
for(%x = 0; %x < %oct; %x++)
{
%b = %obj.getObject(%x);
if(%b.getDatablock().isTrenchDirt)
%b.delete();
}
}
One of the basic programming practices (applies to ALL languages) -- dont delete stuff from a list when your looping over it.
Try something like this instead:
%mct = MainBrickGroup.getCount();
for (%i = 0; %i < MainBrickGroup.getCount(); %i++)
{
%obj = MainBrickGroup.getObject(%i);
%toDelete = new SimSet();
for (%x = 0; %x < %obj.getCount(); %x++)
{
%b = %obj.getObject(%x);
if (%b.getDatablock().isTrenchDirt)
%toDelete.add(%b);
}
while (%toDelete.getCount() > 0)
%toDelete.getObject(0).delete();
}
the funky while loop is because if you just do this:
for (%a=0; %toDelete.getCount(); %a++)
{
%obj = %toDelete.getObject(%a);
%obj.delete();
}
You will get the same errors - this is because when you delete an object, torque is smart enough to delete objects from any lists they are in.