| Blockland Forums > Modification Help |
| How to make script find a brick by its name |
| << < (2/2) |
| Daenth:
--- Quote from: Axolotl on May 28, 2012, 12:31:34 PM ---This will work. This is the easy way. --- Code: ---function findBrickByName(%name) { eval("%currentbrick = \"_\" @ %name;"); if(isObject(%currentBrick) && %currentBrick.getClassName() $= "fxDTSBrick") { return %currentbrick.getID(); } else { return 0; } } --- End code --- Keep in mind that this only looks for single named bricks so I'd appreciate it if somebody did it with Port's way. --- End quote --- Eval is not necessary there nor do you ever want to use it where you don't have to. If you're using this code, switch it to this. --- Code: ---function findBrickByName(%name) { %brick = ("_" @ %name).getID(); if(isObject(%brick) && %brick.getClassName() $= "fxDTSBrick") return %brick; else return 0; } --- End code --- Exact same thing without eval. It will return the most recently placed brick named %name. --- Quote from: Port on May 28, 2012, 12:28:32 PM ---The proper way is looking at the variables on a brick group in order to see all bricks named that (and also to see it for a specific person). --- End quote --- I could see looping through every brick becoming a problem after a few thousand bricks. |
| Greek2me:
--- Quote from: Daenth on May 28, 2012, 01:21:15 PM ---I could see looping through every brick becoming a problem after a few thousand bricks. --- End quote --- No, there are variables in the brickgroup that list the named bricks. |
| Wordy:
--- Quote from: Greek2me on May 28, 2012, 01:27:51 PM ---No, there are variables in the brickgroup that list the named bricks. --- End quote --- | how would you be able to find that out |
| Port:
--- Quote from: Wordy on May 29, 2012, 01:21:11 PM ---| how would you be able to find that out --- End quote --- --- Quote from: Port on May 28, 2012, 06:42:41 AM ---Try invoking the dump() member function of a brick group and look at the output. --- End quote --- |
| Navigation |
| Message Index |
| Previous page |