How do I use the execute command against a named entity?
I would like to do /execute @e[type=Arrow,CustomName:"Flare"] ~ ~ ~ (very long command that I am doing) but it doesn't let me. Whats wrong with it?
Best Answer
CustomName is a NBT tag for entities, not a target selector argument. To select a entity with a custom name via target selector you need to use @e[name=<CustomName>].
If you wish to use the NBT tag or multiple NBT tags to select a entity, you need to create a scoreboard objective in which you set the entities with the desired NBT tag using the Partial NBT Test parameter of scoreboard, then select the entities with the specified score:
Setup:
/scoreboard objectives add selector dummy
Clock (20 tps):
/scoreboard players set @e selector 0 //Reset the score
/scoreboard players set @e selector 1 {<Desired NBT Tags>} //Set the score of all entities with the specified NBT Tags to 1
/execute @e[score_selector_min=1] <x> <y> <z> <Command> //Selects all entities that have been marked by the last command block and executes a command on them
Pictures about "How do I use the execute command against a named entity?"



How do you use the execute command?
How to Enter the CommandHow do you get a command block to say something with a name?
Typing "/tp @p @e[type=mobtype]" will move the player to them. By adding a comma after "mobtype" and placing the argument "name=", players can also move entities. Specifically, those that have been presented with a nametag.Can you teleport to a named entity in Minecraft?
For the command to kill a player or other entity, see Commands/kill. /execute executes another command but allows changing the executor, changing the position and angle it is executed at, adding preconditions, and storing its result.Quick Tip: How To Teleport YOURSELF To A Named/Tagged Entity
More answers regarding how do I use the execute command against a named entity?
Answer 2
you are using /execute @e[type=Arrow,CustomName:"Flare"] ~ ~ ~ While you should use /execute @e[type=Arrow,name:"Flare"] ~ ~ ~ Don't use CustomName just use name ('n' shouldn't be in Caps)
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Andrea Piacquadio, Anete Lusina, Klaus Nielsen, Sora Shimazaki
