Commands/function

Runs commands founds in the corresponding function file with command execution context (executor, execution position, angles, etc) of the /function command.
, runs a function or all functions in a tag from a datapack.
, Runs a function from a behavior pack.
== Syntax ==
* Java Edition
: function <name> [<arguments>|with (block <sourcePos>|entity <source>|storage <source>) [<path>]]
* Bedrock Edition
: function <name: filepath>
== Arguments ==
: 
: 
: 
: 
: 
: (in entity <target> mode)
: 
: (in storage <target> mode)
: 
: 
: 
== Result ==
== Output ==
:
:Success count is the sum of success counts of all commands ran in the function/functions plus 1 (this command itself).
:For example,
::foo:bar1
:::function foo:bar2
::foo:bar2
:::function foo:bar3
::foo:bar3
:::say hi
::The success count of is 1 (one command in foo:bar3) + 1 (this command itself) = 2.
::The success count of is 2 (from above) + 1 (this command itself) = 3.
::The success count of 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 is 1(one command in foo:bar3).
::The chat output count of is 1 (one command in foo:bar2) + 1 (one command in foo:bar3) + 1 (one embedded function) = 3.
::The chat output count of 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, always returns 1. Otherwise, returns 0.
:If successful, the return value of is the same as chat output count. Otherwise, returns 0.
== Examples ==
* : 
** To run a function located at data/custom/functions/example/test.mcfunction in a loaded data pack: 
** To run all functions in a function tag located at data/custom/tags/functions/example/test.json: 
** 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
** To run a function macro with arguments a=42, b="example": /function custom:example/test {a: 42, b: "example"}
** To run a function macro with arguments from storage custom:storage: /function custom:example/test with custom:storage
== History ==
== See also ==
* – To run function in batch, every tick, or on server (re)load.
== References ==
de:Befehl/function
es:Comandos/function
ja:コマンド/function
pt:Comandos/function
ru:Команды консоли/function
uk:Команди консолі/function
zh:命令/function