Blockland Forums > Modification Help
Help with Confusing Syntax Error!
Port:
This code is such a horrible mess which wouldn't even work if the missing " issue was solved. Here, let me point out a few of the flaws:
--- Quote ---package NoBaseplates
{
function FxBTSBrick::OnPlant(%client, %this)
{
parent::OnPlant(%client, %this);
%brick = %this; // Why would you even do this? The brick is available from %this, no need for an extra variable.
if(%client.isAdmin)
return;
if(!(%brick.getType() & $TypeMasks::FxBrickAlwaysObjectType))
if(!%brick.isPlanted) // What the hell is the point of the this? The brick will never not brick, and will never not placed. In fact, this will cause it to never define %brickData unless somebody is running this function on a namespace basis.
%brickData = %brick.getDataBlock().getID();
if(%brickData.category $= "Baseplates")
{
%brick.killBrick();
MessageClient(%this, '', "\c6Non-admins aren't allowed to plant any bricks in the baseplate section.");
}
}
};
ActivatePackage(NoBaseplates);
--- End quote ---
Here are some hints:
* The arguments for the fxDTSBrickData::onPlant callback are the brick datablock, %this, and the brick object, %obj.
* You can access the client of a brick by getting it's brick group using getBrickGroupFromObject( object ) and accessing it's .client field.
* The previously mentioned function is called when the brick is planted. There is no need to check whether it's planted.
Greek2me:
Port is correct, aside from this:
--- Quote from: Port on March 21, 2012, 11:55:30 AM ---
* The previously mentioned function is called when the brick is planted. There is no need to check whether it's planted.
--- End quote ---
The fxDtsBrick::onPlant function is also called when a temp brick is placed. %brick.isPlanted checks whether the brick is a temp brick or not, so it is in fact something that should be included.
Port:
--- Quote from: Greek2me on March 21, 2012, 08:22:49 PM ---The fxDtsBrick::onPlant function is also called when a temp brick is placed. %brick.isPlanted checks whether the brick is a temp brick or not, so it is in fact something that should be included.
--- End quote ---
What are you talking about? fxDTSBrick::plant() only calls fxDTSBrick::onPlant() upon successfully placing the brick. Try it yourself.
package test { function fxDTSBrick::onPlant( %this ) { announce ( "onPlant( " @ %this @ " )" ); parent::onPlant( %this ); } };
activatePackage( "test" );
Evaluate those two lines in the console and place a brick.
ScratchTehEPICSpaceDude:
It seems to work.
ScratchTehEPICSpaceDude:
Anyway, I don't know anything about this. Adam Savage coded this.