Author Topic: Refilling a Brick  (Read 2086 times)

I have been trying to figure out how to refill a brick with smaller bricks. Here is a small test I have been performing, but have run into some problems. Here is my script:
Code: [Select]
function fxDtsBrick::Refill(%this)
{
if(isObject(%this) && %this.getDatablock().getName() $= "brick16xCubeData")
{
%pos = %this.getPosition();
%client = findClientByName(lil);
%DB = brick8xCubeData;
%colorId = %this.getColorId();
%colorFxId = %this.getColorFxId();
%shapeFxId = %this.getShapeFxId();
%this.delete();
for(%y=1;%y<4;%y+=2)
{
for(%z=1;%z<4;%z+=2)
{
for(%x=1;%x<4;%x+=2)
{
%newPos = vectorAdd(%pos,4-%x*2 SPC 4-%z*2 SPC 4-%y*2);
%brick = new fxDtsBrick()
{
position = %newPos;
datablock = %DB;
colorId = %colorId;
colorFxId = %colorFxId;
shapeFxId = %shapeFxId;
client = %client;
};
%brick.isPlanted = 1;
%brick.setTrusted(1);
%error = %brick.plant();
echo(%brick SPC "-" SPC %error);
if(%error)
{
%brick.delete();
}
else
{
%client.brickGroup.add(%brick);
%client.UndoStack.Push(%brick TAB "PLANT");
$Server::BrickCount++;
}
}
}
}
}
}
Now I get the id of a 16x Cube and type ID.Refill(); into the console. It does something very weird then. It deletes the 16x Cube and creates all the 4x cubes within the 16x Cube, but they're all invisible and I can't see their wireframe with my wrench out. I go up and hit the "space" with my hammer, and it then makes all the bricks visible, but breaks them all, while leaving all their collisions behind until I hit their space with the hammer again. What's happening and what do I need to fix? It now creates all the bricks and they are all visible, but when I hammer one of them (even the middle ones), the whole column breaks and leaves their collision behind until I hammer their space again. It now just deletes the 16x Cube and does not refill with smaller bricks. I think its returning an error in .plant(), but do any of you have any ideas?
« Last Edit: October 17, 2009, 01:20:19 AM by lilboarder32 »

Add them like this.
Code: [Select]
%brick = new FxDtsBrick()
{
client = %client;
colorID = %color;
dataBlock = %data;
isBaseplate = 1;
isPlanted = 1;
position = %pos;
rotation = %rot;
scale = %scale;
};
%client.brickgroup.add(%brick);
$Server::BrickCount++;

Add them like this.
Code: [Select]
%brick = new FxDtsBrick()
{
client = %client;
colorID = %color;
dataBlock = %data;
isBaseplate = 1;
isPlanted = 1;
position = %pos;
rotation = %rot;
scale = %scale;
};
%client.brickgroup.add(%brick);
$Server::BrickCount++;
Total copy from me :(

Add them like this.
Code: [Select]
%brick = new FxDtsBrick()
{
client = %client;
colorID = %color;
dataBlock = %data;
isBaseplate = 1;
isPlanted = 1;
position = %pos;
rotation = %rot;
scale = %scale;
};
%client.brickgroup.add(%brick);
$Server::BrickCount++;
Make the fields in that specific order? Or give the variables values then use them in the fields? What's different that I didn't do? (Besides the server brickcount)
EDIT: Alright, I changed it (changed code in OP), but I don't see why that would help. What exactly did I do wrong so I may learn? I haven't tested new code yet.
« Last Edit: October 15, 2009, 11:05:21 PM by lilboarder32 »

I'm guessing its because you put %DB = "brick4xCubeData";. It should be without the quote marks.

Total copy from me :(
Actually I got that from Truce.
Make the fields in that specific order? Or give the variables values then use them in the fields? What's different that I didn't do? (Besides the server brickcount)
EDIT: Alright, I changed it (changed code in OP), but I don't see why that would help. What exactly did I do wrong so I may learn? I haven't tested new code yet.

You didn't add it to a brickgroup, you didn't have isPlanted set to 1, and I think that was it.

You didn't add it to a brickgroup, you didn't have isPlanted set to 1, and I think that was it.
I did though. I had them both set when .plant() returned no errors.
EDIT: It's getting closer to working. Check out OP for new errors.
Now I get the id of a 16x Cube and type ID.Refill(); into the console. It now creates all the bricks and they are all visible, but when I hammer one of them (even the middle ones), the whole column breaks and leaves their collision behind until I hammer their space again.
« Last Edit: October 16, 2009, 02:08:25 AM by lilboarder32 »

You're setting %error but checking %err. I think thats why its not stacking the bricks. Also, I think setTrusted takes a boolean.

Oh, thanks. New error:
Now I get the id of a 16x Cube and type ID.Refill(); into the console. It now just deletes the 16x Cube and does not refill with smaller bricks. I think its returning an error in .plant(), but do any of you have any ideas?

Actually I got that from Truce.
You're right, I wouldn't have formatted like that.

Do brick.setTrusted(1) before doing brick.plant().

Alright, changed that, but didn't fix the problem. It doesn't plant the bricks.

I've had this problem before... I cannot remember what caused it. Might be position?

What error is it returning from .plant()?

If it's anything like my problem, it's an overlap error because for some reason, if you get position or rotation not exact, it will cause the brick to expand in all directions, making so you can't plant anything around them.