Author Topic: Brick Changing  (Read 561 times)

Code: [Select]
      %gt = vectorAdd(%this.getPosition(), %obj.vehicleOffset);
      if(%obj.getPosition() $= %gt)
         return;
      %obj.setName("tempCopy_fxDTSBrick");
      %new = new fxDTSBrick(tempCopy2_fxDTSBrick : tempCopy_fxDTSBrick) {
         position = %gt;
         isPlanted = false;
      };
      %new.setName(%obj.getName());
      %new.setItem((isObject(%item = %obj.item.dataBlock) ? %item : -1));
      if(isObject(%obj.getGroup()))
         %obj.getGroup().add(%new);
      %new.setTrusted(1);
      %new.isPlanted = true;
      %new.plant();
      %obj.delete();
What is wrong with the above code?

Set isPlanted to 1 inside the creation of %new.

This is what I currently have.
Code: [Select]
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.
« Last Edit: January 29, 2011, 06:09:43 AM by Bauklotz »

I can't see the error, but I'm going to be the first to point out that this is going to be horribly implemented.

You're not first. I was first.  :cookieMonster: