This feature is exclusive to Java Edition.
Commands/infobox
Runs a function.
- Syntax
- Java Edition
function <function>
- Arguments
- function
- Must be of the format
namespace:path/to/function/file.
- Must be of the format
- Result
- Fails if the argument is not specified correctly.
- If successful, runs a function through the entity or commandblock which ran the /function command.
- Examples
- To run a function located at 'data/functions/custom/example/test.mcfunction':
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
- See also
- gamerule gameLoopFunction – Runs a function every tick.