Author Topic: Finding a brick by name  (Read 1002 times)

Allo.

I haven't done much scripting for Blockland, and I had no luck with search.

I know how to iterate through objects and see if an object is a brick, but is it possible to figure out what the brick's name is (the name a player gives the brick)?


Code: [Select]
for(%i = serverConnection.getCount()-1; %i > 0; %i--) {

%object = serverConnection.getObject(%i);

if(%object.getClassName() $= "fxDTSBrick") {

//Now what?
         
}
}

The brick's name is getSubStr(%object.getName(),1,strLen(%object.getName())-1);

%object.getName() returns an empty string.

:C



Would I have to cast the object into a fxDTSBrick?
Eh, I duno if Torque can even do that, but I'll search for it and give it a shot.


Edit: Recasting the brick object didn't work, at least doing it the way it's done in C++. It returns 0.

Hmm...
« Last Edit: July 30, 2010, 07:05:59 PM by Snaily »

getBrickName(), getName(), and getPrintName() all return an empty string.

Through the console, I can change the same brick's attributes, so the brick does exist and it does have a name.



Oh, and if this is the wrong section, I'm sorry.

Do NOT search through every brick. You can search every BL_ID's brickgroup for this. The brickgroup contains all bricks that the player has named.

This loops through every named brick in the server:
Code: [Select]
for(%a = 0; %a < MainBrickGroup.getCount(); %a++)
{
    %brickgroup = MainBrickGroup.getObject(%a);
    for(%b = 0; %b < %brickgroup.NTNamecount; %b++)
    {
%name = %brickgroup.NTName[%b];
%obj = %brickgroup.NTObject_[%name];
if(%name $= "brickname")
{
   
}
    }

}

That worked, thanks.

Yeah, I wasn't real happy about the idea of going through every single brick either; I'm glad there's a way to narrow that down as well.