Author Topic: Deleting Brick  (Read 1231 times)

Code: [Select]
function fxDTSBrick::replaceBrick(%this, %newBrick)
{
%brickOffset = ((%newBrick.getDataBlock().brickSizeZ / 5) / 2) - ((%this.getDataBlock().brickSizeZ / 5) / 2);
%brickGroup = getBrickGroupFromObject(%this);

%posX = getWord(%this.position, 0);
%posY = getWord(%this.position, 1);
%posZ = getWord(%this.position, 2) + %brickOffset;

%this.delete();

%newBrick.setTransform(%posx SPC %posy SPC %posz);
%newBrick.plant();
%newBrick.setTrusted(1);
%brickGroup.add(%newBrick);
}

Everything works for this besides it appears that the new brick doesn't actually exist. I can't use a wrench on it or delete it or anything, but it shows up in my brick count. If I use killBrick instead of delete it works though. The only thing wrong with that is I don't want the sound and animation that comes with it.

When %newBrick is created, set the isPlanted field on it to true.

I set the newBrick isPlanted to true when I create it. Would I have to set it again in the function?


Code: [Select]
function fxDTSBrick::replaceBrick(%this, %newBrick)
{
%brickOffset = ((%newBrick.getDataBlock().brickSizeZ / 5) / 2) - ((%this.getDataBlock().brickSizeZ / 5) / 2);
%brickGroup = getBrickGroupFromObject(%this);

%posX = getWord(%this.position, 0);
%posY = getWord(%this.position, 1);
%posZ = getWord(%this.position, 2) + %brickOffset;

%this.delete();
%this.isPlanted = false;

%newBrick.setTransform(%posx SPC %posy SPC %posz);
%newBrick.plant();
%newBrick.setTrusted(1);
%brickGroup.add(%newBrick);
}

It turns out setting isPlanted of the old brick to false fixes it.