Skip to content
WikilyWIKILY
All games23 Wikis · pick your game
Commands and cheatsAll commands

Switch game

23 Wikis · pick your game
/function

Command

/function

Runs a function from a data pack, or every function in a function tag.

Syntax

/function <name>
/function <name> <arguments>
/function <name> with (block <source>|entity <source>|storage <source>) [<path>]

Arguments

ArgumentKind of valueWhat to type
<name>FunctionThe id of the function, for example my_pack:setup, or a function tag starting with #.
<arguments>Data in bracesThe macro values as a data compound, for example {name:"Alex"}.
<source>Block positionFor with: the block position, the single entity or the storage id the macro values are read from.
<path>Data pathFor with: the data path of the compound that holds the macro values. Optional.

Details

Permission level2: operators, worlds with cheats on, command blocks and functions
Works inOperators on multiplayer servers, singleplayer worlds with cheats enabled, and command blocks and functions.
ResultReports "Running function" with the function id. If a function returns a value, it also reports "Function ... returned ...", and that value is the number /execute store saves. When several functions of a tag return values, the result is their sum.
Function tagsA name starting with # runs every function in that function tag. If the tag contains no functions, the command fails with "Can't find any functions".
Arguments for macrosFunctions that contain macro lines need values. Write them as a data compound after the name, or read them from a block, entity or storage with the with sub-command.
withwith block, with entity and with storage take the values from existing data. An optional path picks a part of that data, which must be a compound; otherwise the command fails with "Expected Compound".
Permission inside functionsCommands inside the function run with permission level 2 at most, even if the function is started by someone with a higher level, and they do not print their own output.
Missing valuesIf a macro value is missing or a macro line becomes an invalid command, the command fails with "Failed to instantiate function".

Examples

/function my_pack:setup

Runs the function setup from the data pack namespace my_pack.

/function #my_pack:start_round

Runs every function in the function tag start_round.

/function my_pack:greet {name:"Alex"}

Runs the function greet and fills its macro value name with Alex.

/function my_pack:greet with storage my_pack:settings greeting

Runs the function greet with the macro values stored under greeting in the storage my_pack:settings.

Join the creator communityThe people who build the Minecraft Java Edition wiki are on our Discord. Ask questions or suggest pages.Join Discord (opens Discord in a new tab)