Blockland Forums > Modification Help

Deleting bricks of a certain color

Pages: (1/4) > >>

Treynolds416:

I decided to make a script that could delete all of the bricks of a specified color from a build.
My method was to edit the business lines of the save file and rewrite to a new file, which I would copy/paste back in.

--- Code: ---//Client_ColorDestroy

function ColorDestroyList(%file, %colorN)
{
new scriptObject(LineSO) {}
%file = expandFilename(%file);
if(isFile(%file))
{
%fileObject = new FileObject();
if(%fileObject.OpenForRead(%file))
{
for(%l=0;%l<256000;%l++)
{
%line = %fileObject.readline();
%brickVal = getWord(%line,8);
if(%brickVal != %colorN)
{
LineSO.value[%SoL] = %line;
%SoL++;
}
else
{
return;
}
}
%SoL = $SOL
%file.close();
%file.delete();
deletecolorso();
colordestroywrite();
}
else
{
echo("ColorDelete() - Error opening the .bls file "@%file);
}
%fileObject.delete();
}
else
{
echo("ColorDelete() - Error locating the .bls file "@%file);
}
}

function ColorDestroyWrite(%file)
{
%obj.save(%file);
}

function DeleteColorSO(%this)
{
LineSO.delete();
}
--- End code ---

Since I'm making a topic and know this isn't the best way to do this, you might as well tell me a better option if you know one.

So
1) Tell me what I did wrong with this code
2) Tell me how else I could go about doing this

otto-san:

Someone was trying to do this once.

You can loop through the main brick group and find every brick with the color ID you're looking for and delete them. Much simpler, but regardless of what way you go about doing it you have to know every single color ID and also possibly make functions for every single one.

Iban:

Okay, tons of things.

1. Nowhere in this code does it actually attempt to do anything to any bricks. It's just a mess trying to read a file.
2. new scriptObject(LineSO){} - I have no idea what this is supposed to do. LineSO is never referenced anywhere. There's no semicolon after the object declaration so it's going to cause a syntax error.
3. Why the forget do you have two functions outside of the actual function that have no purpose other than deleting script objects?
4. I just realized that the file is called Client_ColorDestroy. How is this a client mod? What.

I don't even know why you want it to read a file. I have this in some random "Handy Function" package I built.


--- Code: ---function deleteAll(%brickType)
{
// Did we supply a valid datablock?
if(isObject(%brickType))
{
%killList = "";

// Loop through all brickgroups.
for(%a = 0; %a < MainBrickGroup.getCount(); %a++)
{
%bg = MainBrickGroup.getObject(%a);

// Loop through every brick in this brickgroup.
for(%b = 0; %b < %bg.getCount(); %b++)
{
%brick = %bg.getObject(%b);

// Test if the bricktype of the selected brick
if(%brick.getDatablock().getID() == %brickType.getID())
{
%killList = setField(%str, getFieldCount(%killList), %brick.getID());
}
}
}

for(%a = 0; %a < getFieldCount(%killList); %a++)
{
%brick = getField(%killList, %a);
%brick.killBrick();
}

echo("Destroyed" SPC getFieldCount(%killList) SPC "Brick(s).");
}
}

--- End code ---

Just change it to delete if the color ID matches the ID entered in the parameters.



--- Quote from: otto-san on May 25, 2011, 07:46:46 PM ---Someone was trying to do this once.
--- End quote ---
How could he fail? This is not a complex issue.

otto-san:

Not really complex at all, just annoying.

Iban:


--- Quote from: otto-san on May 25, 2011, 07:51:43 PM ---Not really complex at all, just annoying.

--- End quote ---
not really.


--- Code: ---function descriminateBricks(%findColor, %replaceColor)
{
%killList = "";

// Loop through all brickgroups.
for(%a = 0; %a < MainBrickGroup.getCount(); %a++)
{
%bg = MainBrickGroup.getObject(%a);

// Loop through every brick in this brickgroup.
for(%b = 0; %b < %bg.getCount(); %b++)
{
%brick = %bg.getObject(%b);

// Test if the bricktype of the selected brick
if(%brick.getColorID() == %findColor)
{
%killList = setField(%str, getFieldCount(%killList), %brick.getID());
}
}
}

for(%a = 0; %a < getFieldCount(%killList); %a++)
{
%brick = getField(%killList, %a);

if(isObject(%brick))
{
if(%replaceColor $= "")
{
%brick.killBrick();
}
else
{
%brick.setColor(%replaceColor);
}
}
}

echo("Acted upon" SPC getFieldCount(%killList) SPC "Brick(s).");
}
--- End code ---

"And you're done."

Pages: (1/4) > >>

Go to full version