Minecraft Wiki
Minecraft Wiki
Permission level

2‌[JE only]
1‌[BE only]


Cheat only‌[BE only]

Runs commands founds in the corresponding function file.

In Java Edition, runs a function or all functions in a tag from a datapack.
In Bedrock Edition, Runs a function from a behavior pack.


  • Java Edition
function <name>
  • Bedrock Edition
function <name: filepath>


JE<name>: function
BE: name: filepath: CommandFilePath

In Java Edition, must be a resource location, which refers to a single function, or one prefixed with a #, which refers to a function tag. In Bedrock Edition, must be of the format path/to/function/file, which refers to a function located at [behavior_pack]/functions/path/to/function/file.mcfunction.


CommandTriggerJava EditionBedrock Edition
anythe arguments are not specified correctly Unparseable Failed
the specified functions or function tags do not exist Failed
On successRuns the function(s) through the command executor which ran the /function command.


CommandEditionSituationSuccess Count/execute store success .../execute store result ...
anyJava EditionOn fail000
On success when executed not by a functionthe number of all commands executed in the function(s) plus 1 (this command itself)1the number of commands executed (whether successfully or not) plus the number of embedded functions.
On success when executed in a functionN/A10
Bedrock EditionOn fail0N/AN/A
On success1N/AN/A

In Java Edition:[1][2]

Success count is the sum of success counts of all commands ran in the function/functions plus 1 (this command itself).
For example,
function foo:bar2
function foo:bar3
say hi
The success count of /function foo:bar3 is 1 (one command in foo:bar3) + 1 (this command itself) = 2.
The success count of /function foo:bar2 is 2 (from above) + 1 (this command itself) = 3.
The success count of /function foo:bar1 is 3 (from above) + 1 (this command itself) = 4.
Output message displayed in chat returns the number of commands ran (not the number of commands that succeed) plus the number of embedded functions called by a function.
The chat output count of /function foo:bar3 is 1(one command in foo:bar3).
The chat output count of /function foo:bar2 is 1 (one command in foo:bar2) + 1 (one command in foo:bar3) + 1 (one embedded function) = 3.
The chat output count of /function foo:bar1 is 1 (one command in foo:bar1) + 1 (one command in foo:bar2) + 1 (one command in foo:bar3) + 2 (two embedded functions) = 5.
If successful, /execute store success always returns 1. Otherwise, returns 0.
If successful, the return value of /execute store result is the same as chat output count. Otherwise, returns 0.


  • In Java Edition:
    • To run a function located at data/custom/functions/example/test.mcfunction in a loaded data pack: /function custom:example/test
    • To run all functions in a function tag located at data/custom/tags/functions/example/test.json: /function #custom:example/test
    • To run a function if there is a sheep within a radius of 2 blocks: /execute if entity @e[type=sheep,distance=..2] run function custom:example/test
    • To run a function unless the executor is a player: /execute unless entity @s[type=player] run function custom:example/test


Java Edition
1.12pre1Added /function.
1.1317w49b/function now accept function tags as the argument.
Removed [if/unless] arguments in favor of /execute [if/unless].
Bedrock Edition
1.8.0beta /function.

See also[]

  • /tag – To run function in batch, every tick, or on server (re)load.