Author Topic: Parent one brick to another so you can break both?  (Read 425 times)

I need a way to break one brick, and it breaks the other, would something like this work?

function fxDTSbrick::OnPlant(%asdf)
{
%brick = new brick stuff
}

function fxDTSbrick::OnDeath(%a)
{
%brick.delete();
}

I am aware this actual function would never work properly, its just to get my point across

Code: [Select]
package whatever
{
function fxDTSBrick::onRemove( %this )
{
other_brick.delete();
parent::onRemove( %this );
}
};
activatePackage( whatever );

I'm sort of uncertain whether will work in all cases, but it pretty much should work.
Also, obviously replace "other_brick" with the actual brick you want to destroy.

If this is the same project as that stuff where you wanted to make other bricks upon planting a brick, you should store the individual newly created bricks as fields on the brick and then read those fields when you need to destroy the brick.

Code: [Select]
package whatever
{
function fxDTSBrick::onRemove( %this )
{
other_brick.delete();
parent::onRemove( %this );
}
};
activatePackage( whatever );

I'm sort of uncertain whether will work in all cases, but it pretty much should work.
Also, obviously replace "other_brick" with the actual brick you want to destroy.

If this is the same project as that stuff where you wanted to make other bricks upon planting a brick, you should store the individual newly created bricks as fields on the brick and then read those fields when you need to destroy the brick.
So then what I put in the OP would work, considering yours is just a shorter version :/

and I'm not sure I get what you mean by fields, can you give me an example?
« Last Edit: December 11, 2011, 01:44:22 AM by soba »

I did this in an abandoned project of mine, when you planted a certain brick it would plant another next to it, and when you destroy one the other would get destroyed.
Something like this

Code: [Select]
function brickDatablockName::onPlant(%this)
{
Parent::onPlant(%this);
%this.otherSide = new brick stuff, other stuff for planting, etc
%this.otherSide.otherSide = %this;
}

function brickDatablockName::onDeath(%this)
{
Parent::onDeath(%this);
if(isObject(%this.otherSide))
%this.otherSide.killBrick();
}
Packaged of course
« Last Edit: December 11, 2011, 02:56:00 PM by Headcrab Zombie »