Blockland Forums > Modification Help

Finding supported bricks

Pages: << < (4/6) > >>

Treynolds416:

Do they give all of the bricks connected, or just the ones directly below?

Greek2me:

I'm guessing that it's just direct connections. You could then loop through those and repeat on each of them, and so on until you find the ground or run out of downBricks to loop through.

Slicks555:


--- Code: ---function getSupportedBricks(%brick)
{
   %ss = new simSet();
   for(%i=0; %i<%brick.getNumUpBricks();%i++)
      %ss.add(%brick.getUpBrick(%i));
   %brick.setName(oldBrick);
   %newbrick = new fxDTSBrick(newBrick:oldBrick);
   %newbrick.setName();
   %brick.getGroup().add(%newbrick);
   %brick.delete();
   %supportBricksSet = new simSet();
   for(%i=0; %i<%ss.getCount(); %i++)
   {
      if(!%ss.getObject(%i).hasPathToGround())
         %supportBricksSet.add(%ss.getObject(%i));
   }
   %ss.delete();
   %newbrick.plant();
   %newbrick.setTrusted(1);
   return %supportBricksSet;
}

--- End code ---
This should return a group containing bricks that are supported by provided brick. This will, however, clear the events on the brick. There are ways around that, I was just too lazy to put it in.

Treynolds416:

That doesn't look it works...
Could you explain it maybe?

Slicks555:


--- Quote from: Treynolds416 on April 29, 2012, 05:18:19 PM ---That doesn't look it works...
Could you explain it maybe?

--- End quote ---
Yeah, sure.


--- Code: ---function getSupportedBricks(%brick)
{
   %ss = new simSet(); // Create a new group to store all potential supportees
   for(%i=0; %i<%brick.getNumUpBricks();%i++)
      %ss.add(%brick.getUpBrick(%i)); //Add all potential suportees to group
   %brick.setName(oldBrick); // Name the brick in question oldBrick
   %newbrick = new fxDTSBrick(newBrick:oldBrick); // Duplicate this brick, but leave it as a ghost brick so it won't continue to support the bricks later.
   %newbrick.setName(); // Clear the name of the brick
   %brick.getGroup().add(%newbrick); // Add the new brick into the client's brickgroup, it's going to be replacing it later and we want it functional
   %brick.delete(); // Get rid of the brick in question. This will leave all bricks it's supporting still there, and we can check if they're floating.
   %supportBricksSet = new simSet(); // Make a group to put the definitely supported bricks in
   for(%i=0; %i<%ss.getCount(); %i++) //Loop through potential supportees
   {
      if(!%ss.getObject(%i).hasPathToGround()) //If they are floating
         %supportBricksSet.add(%ss.getObject(%i)); //Add them to the definitely supported brick group
   }
   %ss.delete(); // Get rid of the potential group. We don't need it anymore.
   %newbrick.plant(); // Plant the replacement brick, after all we deleted the brick we were testing.
   %newbrick.setTrusted(1); // Just makes things work. Part of brick planting.
   return %supportBricksSet; // Output the list of supported bricks
}

--- End code ---


Pages: << < (4/6) > >>

Go to full version