
Command
/function
Runs a function from a data pack, or every function in a function tag.
| /function <name> |
| /function <name> <arguments> |
| /function <name> with (block <source>|entity <source>|storage <source>) [<path>] |
| Argument | Kind of value | What to type |
|---|---|---|
| <name> | Function | The id of the function, for example my_pack:setup, or a function tag starting with #. |
| <arguments> | Data in braces | The macro values as a data compound, for example {name:"Alex"}. |
| <source> | Block position | For with: the block position, the single entity or the storage id the macro values are read from. |
| <path> | Data path | For with: the data path of the compound that holds the macro values. Optional. |
| Permission level | 2: operators, worlds with cheats on, command blocks and functions |
| Works in | Operators on multiplayer servers, singleplayer worlds with cheats enabled, and command blocks and functions. |
| Result | Reports "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 tags | A 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 macros | Functions 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. |
| with | with 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 functions | Commands 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 values | If a macro value is missing or a macro line becomes an invalid command, the command fails with "Failed to instantiate function". |
/function my_pack:setupRuns the function setup from the data pack namespace my_pack.
/function #my_pack:start_roundRuns 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 greetingRuns the function greet with the macro values stored under greeting in the storage my_pack:settings.

