Commands/function

From Minecraft Wiki
Jump to: navigation, search
Java Edition.png
function
Restrictions

Operator

First introduced

1.12 (1.12-pre1)

Runs a function.

Syntax
  • Java Edition
function <function>
Arguments
function
Must be of the format namespace:path/to/function/file.
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.


Promotional Content