/ Execute

The `/execute` command in Minecraft Bedrock Edition is one of the most powerful commands, allowing you to run commands based on specific conditions or actions. Below we’ll explain its basic structure, as well as some common use cases.

Command logic: /op [origin] [position] [command]

[origin]: The entity or player on which the command is based.
[position]: Coordinates where the command will be executed.
[command]: The action that will take place.


Run a Command at a Specific Player's Location

This command allows you to execute an action based on a player’s location. For example, to summon a lightning bolt at a player's position, you would use:

/execute positioned ~ ~ ~ as @p run summon lightning_bolt

In this case, `@p` refers to the nearest player, and the tilde symbols (`~`) indicate that the command should be executed at the player’s current position.


Run a Command Based on an Entity's Condition

The `/execute` command can also be used to run commands based on the conditions of entities. For example, if you want to detect whether a player is standing on a block of grass, you can use:

/execute as @p positioned ~ ~ ~ if block ~ ~-1 ~ grass run say "You are on grass!"

This command checks if the block directly below the player (`~ ~-1 ~`) is grass, and if so, it executes the `say` command to send a message in the chat.

GIF showing detect condition in execute command

Chain Multiple Commands

You can also use `/execute` to chain multiple commands together. For example, if you want to check a player’s position and then execute multiple actions, you can chain them as follows:

/execute as @p positioned ~ ~ ~ if block ~ ~-1 ~ grass run summon wolf

This command checks if the player is on grass and summons a wolf at their position.

GIF showing multiple chained commands

Teleport a Player Based on Their Condition

You can use `/execute` to run advanced commands based on conditions and actions. For example, teleporting a player to a specific location if they are standing on sand:

/execute as @p positioned ~ ~ ~ if block ~ ~-1 ~ sand run tp @p 100 50 100

This command checks if the player is standing on sand and teleports them to the coordinates (100, 50, 100).


Execute Command Variants

The `/execute` command can be customized in many ways. Here are some common variants you can explore:

/execute as [entity] run [command]: Executes the command as a specific entity.

/execute as [entity] at [entity] run [command]: Runs the command at the location of a specific entity.

/execute if [condition] run [command]: Executes the command only if a specified condition is met.