Skip to main content

/function

Runs a function or function tag from a data pack. Functions are .mcfunction files containing a list of commands.

Category
Logic
Permission Level
Game Master
Version Added
1.12

Syntax

/function <name> [with <storage> [<path>]]

Parameters

NameTypeRequiredDescription
nameresourceRequiredThe function or function tag to execute (e.g., mypack:my_function or #mypack:my_tag).
storageresourceOptionalA data storage to pass as macro arguments (1.20.2+, used with 'with' keyword).
pathnbt_pathOptionalThe NBT path within the storage for macro arguments.

Examples

/function my_pack:setup

Runs all commands in the my_pack:setup function.

/function #minecraft:load

Runs all functions in the minecraft:load function tag.

/function my_pack:greet with storage my_pack:data player

Runs the greet function with macro arguments from a data storage.

Common Mistakes

Notes

Functions run sequentially, one command per line. The function inherits the execution context of the calling command. Since 1.20.2, macros allow parameterized functions using $() syntax.

Related Commands

Need a Minecraft server?

Try these commands on Astroworld or host your own server.

Try Astroworld Hosting