/function Command
Runs all commands in a .mcfunction file (or all functions in a function tag when prefixed with `#`). Since 1.20.2, supports macro functions: if the file contains `$`-prefixed macro lines, a compound NBT argument can be passed either as a literal or read from a data source, substituting `$(variable)` placeholders at runtime.
Syntax
function <name> [<arguments>]
function <name> with (block <sourcePos>|entity <source>|storage <resource_location>) [<path>]Permission: 2Edition: Java
Examples
function mypack:setup#function mypack:tick_allfunction mypack:dialog/greet {player: "Steve", reward: 10}function mypack:apply_buff with entity @s CustomDataNotes
Exclusive to Java Edition. Function macros (the `with` and literal-argument forms) require the function file to use `$` macro lines and were introduced in Java Edition 1.20.2. Functions run in the current command context. A `#function_tag` runs every function listed in that tag. Return values from functions can be captured with `execute store result … run function`.