This is what I currently have.
function wheeledVehicle::moveBricks(%this) {
cancel(%this.moveBricks);
if(!isObject(%brk = %this.spawnBrick))
return:
%cnt = %brk.bricks+1;
for(%i=0;%i<%cnt;%i++) {
%obj = %brk.bricks[%i];
if(!isObject(%obj) || %obj $= %brk || %obj.getDataBlock().getName() $= brickJeepBaseplateData)
continue;
%gt = vectorAdd(%this.getPosition(), %obj.vehicleOffset);
if(%this.getPosition() $= %gt)
continue;
%n = %obj.getName();
%obj.setName("tempCopy_fxDTSBrick");
%new = new fxDTSBrick(tempCopy2_fxDTSBrick : tempCopy_fxDTSBrick) {
position = %gt;
rotation = %this.rotation;
isPlanted = true;
};
%new.setName(%n);
%new.setColliding(false);
%new.setItem((isObject(%item = %obj.item.dataBlock) ? %item : -1));
if(isObject(%obj.getGroup()))
%obj.getGroup().add(%new);
%new.setTrusted(1);
%obj.delete();
%new.plant();
}
%this.moveBricks = %this.schedule(1, moveBricks);
}
But the problem is, it keeps deleting %brk (.spawnBrick), and then complaining about that %this doesn't exist when doing %this.schedule.