Author Topic: Clearing only a type of brick  (Read 1808 times)

How do I clear only trench dirt bricks in a script?

You need to first find a member field or a datablock property that distinguishes the brick you want to be deleted from other bricks. Then, loop through all bricks and delete the ones that have that distinguishing property

You need to first find a member field or a datablock property that distinguishes the brick you want to be deleted from other bricks. Then, loop through all bricks and delete the ones that have that distinguishing property
I see

You need to first find a member field or a datablock property that distinguishes the brick you want to be deleted from other bricks. Then, loop through all bricks and delete the ones that have that distinguishing property
He's right.
In this case, all trench dirt brick datablocks have an isTrenchDirt variable set to true.

So, you'd do something like this:
Code: [Select]
%mct = MainBrickGroup.getCount();
for(%i = 0; %i < %mct; %i++)
{
%obj = MainBrickGroup.getObject(%i);
if(!%oct = %obj.getCount())
continue;
for(%x = 0; %x < %oct; %x++)
{
%b = %obj.getObject(%x);
if(%b.getDatablock().isTrenchDirt)
%b.delete();
}
}
I'm not guaranteeing that will work, but it should give you an idea of where to go with this.

It works but only partially
It deletes some of them then it stops with this console error
Quote
Add-Ons/Script_Reset_Map/server.cs (20): Unable to find object: '-1' attempting to call function 'getDataBlock'
BackTrace: ->[resetmap]servercmdresetmap

Set::getObject index out of range on BrickGroup_999999. Index = 102, Size = 65
BackTrace: ->[resetmap]servercmdresetmap

Yes, those are some problems I expected that would run into. That's why I tried to imply you shouldn't use that directly, but I probably should've just said that.

I don't understand, what exactly does if(!%oct = %obj.getCount()) do?

I don't understand, what exactly does if(!%oct = %obj.getCount()) do?
If %obj.getCount() returns false I believe.

I don't understand, what exactly does if(!%oct = %obj.getCount()) do?
it's the same as
%oct = %obj.getCount();
if(!%oct)


and you could also replace if(!%oct) with if(%oct == 0)

If %obj.getCount() returns false I believe.
basically, except that's a more confusing way of stating it because it returns a value that's meant to be an integer and not a boolean


...i think i just realised, if there's no bricks in the brickgroup, does it actually return -1 instead of 0?

and you could also replace if(!%oct) with if(%oct == 0)
But than it would only check if it's 0 instead of false. False counts as 0 and anything below 0 I believe.

But than it would only check if it's 0 instead of false. False counts as 0 and anything below 0 I believe.
0 and false as well as non-numerical strings evaluate to false as a boolean.

Anything else is true.

0 and false as well as non-numerical strings evaluate to false as a boolean.

Anything else is true.
Anything below 0 returns as false also.


Anything below 0 returns as false also.


And when I do
if(!-4){echo(hi);}
it echos nothing.

that's torque for you, i guess.

And when I do
if(!-4){echo(hi);}
it echos nothing.

that's torque for you, i guess.
Do if(!!-4){echo(hi);}

Guys, start your for loop at the highest value and then work down to 0...