Author Topic: is there any way to set the name of a brick based on its color?  (Read 2098 times)

I dont feel like naming every single one of these bricks in a build that i'm building, and they're all one color, so i'm wondering if there's a console command or something that will name them based on color?

This should do the trick:

Code: [Select]
$COL=3;$NAME="_yourName";$bg=clientGroup.getObject(0).brickgroup;for($i=$bg.getCount()-1;$i>=0;$i--){$br=$bg.getObject($i);if($br.getColorID()==$COL)$br.setNTObjectName($NAME);}

I like the idea of making the code terribly messy so the user has to think it through on some level at least.

I like the idea of making the code terribly messy so the user has to think it through on some level at least.
I'm pretty sure the idea was to make it a single line so it can be pasted into the console.

Expanded:

Code: stuff (11 lines)
$COL = 3;
$NAME = "_yourName";

$bg = clientGroup.getObject(0).brickgroup;
for($i = $bg.getCount() - 1; $i >= 0; $i--)
{
   $br = $bg.getObject($i);

   if($br.getColorID() == $COL)
       $br.setNTObjectName($NAME);
}

« Last Edit: June 02, 2015, 01:15:46 AM by Zeblote »

Usage note: $COL is the color index of the color you want. The first color (top left of your paint selector) is ID 0, then it increases downwards until the end of the first column. Then the next number is the first in the second column, etc. $NAME will be the name you want prefixed by "_". So, if you want the brick named "wall" you'd set $NAME = "_wall";

This should do the trick:

Code: [Select]
$COL=3;$NAME="_yourName";$bg=clientGroup.getObject(0).brickgroup;for($i=$bg.getCount()-1;$i>=0;$i--){$br=$bg.getObject($i);if($br.getColorID()==$COL)$br.setNTObjectName($NAME);}

Note: Unless you're using the dedicated server console (important to keep in mind, I suppose), console entries are run with eval inside the ConsoleEntry::eval function's scope, which means that you can use local variables just fine.

oh neat, so in the same line local variables are fine, but need global for multiple console entries