Author Topic: Help with getDownBrick  (Read 1500 times)

Code: [Select]
package test
{
function fxDTSBrick::onRemove(%this)
{
if(%this.isPlanted())
{
%dbrick = %this.getDownBrick(0);
echo(%dbrick.getDataBlock());

}

parent::onRemove(%this);
}
};

When I use getDownBrick it returns null. If anyone can help me out with this more would be nice.
« Last Edit: March 15, 2015, 11:01:33 PM by devildogelite »

The number of bricks below a given brick is variable.  Use %brick.getNumDownBricks(); to get the number of bricks below it.

So would I use that as the parameter for getDownBrick? I think I should of mentioned I'm looking for only the brick directly below the current one.

Is there actually a brick beneath it?

Is there actually a brick beneath it?

Yep, it keeps telling me unable to find object.

Code: [Select]
%position = %this.getPosition();
%radius = (%this.getDataBlock().brickSizeZ / 5) + (1 / 10);

InitContainerRadiusSearch(%position,%radius,$TypeMasks::FxBrickObjectType);
%found = false;

while((%targetObject = containerSearchNext()) !$= 0 && !%found)
{
%offset = ((%this.getDataBlock().brickSizeZ / 5) + (%targetObject.getDataBlock().brickSizeZ / 5)) / 2;

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

%pos = %posX SPC %posY SPC %posZ - %offset;

if(%targetObject.getPosition() $= %pos)
{
echo("found");
%found = true;
}

}

This is what I ended up doing. I know it means that the brick has to be centered directly underneath it but that works for what I want to do. If anyone has suggestions for making this more elegant please let me know.

One more quick question, how come with %radius = (%this.getDataBlock().brickSizeZ / 5) + (1 / 10); it throws an error if I try to use .1 instead of 1/10?

One more quick question, how come with %radius = (%this.getDataBlock().brickSizeZ / 5) + (1 / 10); it throws an error if I try to use .1 instead of 1/10?
Because you have to use 0.1

fxDTSBrick::get____Brick and fxDTSBrick::getNum____Bricks are unusable inside onRemove. Octree cleanup is sort of done prior to onRemove.

One half-acceptable solution to this is to run fxDTSBrick::plant() inside onRemove, then your original code works. The one issue is that you get an error every time this happens: fxDTSBrick::insertIntoTree -- Brick has already been inserted.

fxDTSBrick::get____Brick and fxDTSBrick::getNum____Bricks are unusable inside onRemove. Octree cleanup is sort of done prior to onRemove.

One half-acceptable solution to this is to run fxDTSBrick::plant() inside onRemove, then your original code works. The one issue is that you get an error every time this happens: fxDTSBrick::insertIntoTree -- Brick has already been inserted.

Okay, I was figuring that onRemove made things a bit wonky. Is it normal for onRemove to be slightly laggy? I had an echo in it and it took a couple seconds for it to echo when I removed a brick.

Is it normal for onRemove to be slightly laggy? I had an echo in it and it took a couple seconds for it to echo when I removed a brick.

I had the same issue, so afaik its normal. You could also parent fxDTSBrick::onBreak which happens the moment you kill it, but i recommend using onRemove as well, so it still works when you clear bricks, or the brick is deleted some other way.

fxDTSBrick::onRemove is called when the brick is literally removed from the game. For bricks that are killed with fxDTSBrick::killBrick this happens after the physics animation (it falling and disappearing) is 100% complete which takes a few hundred milliseconds or so. However, it's called instantaneously for bricks that are removed with delete as there is no associated animation.