Author Topic: Detecting the brick(s) planted below a planted brick  (Read 1198 times)

I have a complicated issue where I need for a planted brick to see if it is on top of a "certain brick," which I don't feel is easy to program. I also never heard of anyone needing to do a similar thing to this (or I havent searched enough).

I also seem to have a lot of Coding Help problems lately. Sorry about that.

How would you go fetching the brick name, ID, datablock, or anything that identifies the brick below a planted brick?

As far as starting this, I think an onPlant function would cover this somehow.

Code: [Select]
function fxDTSBrick::onPlant(%brick)
{

        }

This is going to be used for a farming system which the plants need to know if they are on top of a "dirt" brick.

Code: [Select]
package checkBrick {
function fxDTSBrick::onPlant(%brick)
{
%down = %brick.getNumDownBricks();
for(%i = 0; %i < %down; %i++)
{
%dbrick = %brick.getDownBrick(%i);
if(%dbrick.isPlanted())
{
%isAboveCorrectBrick = 1;
break;
}
}
if(%isAboveCorrectBrick)
parent::onPlant(%brick);
else
%brick.schedule(0,delete);
}
};
activatePackage(checkBrick);
This checks if it's directly on top of a brick and deletes it if it's not.
« Last Edit: September 05, 2012, 08:29:02 PM by TripNick »

You're a lifesaver. Sorry for the insult earlier.

I had no idea on how to do this even after pondering for a week or two.

You're a lifesaver. Sorry for the insult earlier.

I had no idea on how to do this even after pondering for a week or two.
Oops, I mistyped something. Fixed it.

EDIT: Wow, I somehow missed that you said planted below. Fixed again, if you didn't figure out the necessary changes yourself.
« Last Edit: September 05, 2012, 07:02:19 PM by TripNick »

As in, you plant a brick on top of a dirt block, and if it sees the brick below is dirt, it doesn't break the brick (the one you planted of course). Just making it clear.

Thank you anyway.

Oh. I guess I'll revert it then.

Right but how might I check the below brick's Ui Name to see if its "Dirt"?

You would see if %brick.getDatablock().uiName $= "Dirt".

This doesn't work because it checks every single brick instead of just the bricks that have the

Code: [Select]
isCrop = true;
datablock property. Thus the dirt thats required to plant crop bricks cant be placed itself.


Im guessing I'd need:
Code: [Select]
%brick.isCrop = true;

Whats wrong with this now?

Code: [Select]
package checkBrick
{
function fxDTSBrick::onPlant(%brick)
{
if(%brick.isCrop)
{
%down = %brick.getNumDownBricks();
for(%i = 0; %i < %down; %i++)
{
%dbrick = %brick.getDownBrick(%i);
if(%dbrick.isPlanted())
{
    if(%dbrick.getDatablock().uiName $= "Dirt")
{
%isAboveCorrectBrick = 1;
break;
}
}
}
if(%isAboveCorrectBrick)
parent::onPlant(%brick);
else
%brick.schedule(0,delete);
}
else
{
parent::onPlant(%brick);
}
}
};
« Last Edit: September 17, 2012, 07:23:45 PM by Randomness »

When you set a datablock property, to check it, you must check it with the datablock. In your code you have if(%brick.isCrop). This will always evaluate to false, because there is no such variable on the brick. What your code should like this is if(%brick.getDataBlock().isCrop)