Minecraft/Commands/execute

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Example1 : /execute at @e setblock ~~~ glass_block places a glass block at the feet of all players, mobs, boats, minecarts, armour stands, ect..

Syntax:

/execute <target: selector (required)> <command (required)>

The target is the entity(s) to effect. The position is where to run the command from, according to target, so ~~~ means where the target is. The command is any command, even another /execute command, may be placed.

Example2: /execute at @a[hasitem={name=diamond}] run say @s "congratulations you found diamonds!"

This command will check all players inventory , if he/she has diamond. If condition is true than it will message the that same player "congratulations you found diamonds!".