| Blockland Forums > Modification Help |
| Parent one brick to another so you can break both? |
| (1/1) |
| soba:
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 |
| Port:
--- Code: ---package whatever { function fxDTSBrick::onRemove( %this ) { other_brick.delete(); parent::onRemove( %this ); } }; activatePackage( whatever ); --- End code --- 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. |
| soba:
--- Quote from: Port on December 11, 2011, 01:00:23 AM --- --- Code: ---package whatever { function fxDTSBrick::onRemove( %this ) { other_brick.delete(); parent::onRemove( %this ); } }; activatePackage( whatever ); --- End code --- 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. --- End quote --- 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? |
| Headcrab Zombie:
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: ---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(); } --- End code --- Packaged of course |
| Navigation |
| Message Index |