Author Topic: Delete all invisible bricks  (Read 1346 times)

I could use a code to delete all bricks that don't have rendering in a way that doesn't also kill bricks supported by them.

Code: [Select]
%mainBrickGroupCnt = mainBrickGroup.getCount();
for(%i = 0; %i < %mainBrickGroupCnt; %i++) {
    %brickGroup = mainBrickGroup.getObject(%i);
    %brickGroupCnt = %brickGroup.getCount();
    for(%j = %brickGroupCnt-1; %j > 0t; %j--) {
        %brick = %brickGroup.getObject(%j);
        if(!%brick.isRendering())
            %brick.delete();
    }
}
« Last Edit: November 22, 2014, 06:12:16 PM by $trinick »

Code: [Select]
    %brickGroupCnt = %brickGroup.getCount();
    for(%j = 0; %j < %brickGroupCnt; %j++) {
           ....
            %j--;
            %brickGroupCnt--;
    }

Why not just
for(%i=brickgroup.getcount();%i>0;%i--) {
  ...
}

I actually don't know. That was the first post I made after I rolled out of bed, so.. guess I just wasn't thinking straight. Edited.

Ok thanks. Now how would I clear only invisible bricks that don't have an item spawned on them?

Change if(!%brick.isRendering()) to if(!%brick.isRendering() && %brick.Item $= "")

Why not just
for(%i=brickgroup.getcount();%i>0;%i--) {
  ...
}

That should be for(%i=%group.getCount()-1;%i>=0;%i--).  Otherwise it'll generate an out-of-index error and miss one brick.