Function (Bedrock Edition)

Functions allow players to run lists of commands using text files with the extension. This page covers how to use functions $$.

Usage
Text files must be placed into a top-level folder named "functions" within a behavior pack, located at com.mojang/behavior_packs/[behavior_pack]/functions.

Subfolders and namespacing
Subfolders can be added to this folder to serve as namespaces.

For example, running the function  runs the file located at [behavior_pack]/functions/sub/foo.mcfunction.

Note: Currently reloads only functions that already exist at the time the game is launched, meaning changes can be made to existing functions but the game must be restarted for newly added functions.

Success results
Upon successfully running a function, a message displays in chat: "Executed [amount] Command(s) from function [function file directory] ." In version 1.12.0 this is "Successfully executed [amount] function entries."

Function syntax
Within the  file, one valid command is placed per line, without the usual forward slash. Players can add comments within the function text file by preceding them with a.

If the first line of the function is  (excluding any commented lines), then the function is not visible in the suggestions for the   command, but can still be called by typing the command manually.

Functions require a minimum engine version specified in the pack file.

This field determines which version of a command to run. The number specified here should match the version number of the game. For example, lets say that was changed in. If your behavior pack has  and runs a function that contains, it runs the older version of fill (as if the version was still  ).

Manifest example
{   "format_version": 1, "header": { "description": "Function worldedit", "name": "Function worldedit", "uuid": "11111111-1111-1111-1111-111111111111", "version": [1, 11, 3], "min_engine_version": [1, 11, 3] },   "modules": [ {           "description": "", "type": "data", "uuid": "22222222-2222-2222-2222-222222222222", "version": [1, 11, 3] }   ] }

Simple function example
test.mcfunction

title @p title Test setblock ~ ~2 ~ diamond_ore say Test
 * 1) this is a comment

More complex function example
BuildHut.mcfunction - this function builds a basic stone and wood house around you. Note that because the function runs commands in order, the glass windows and wooden door replace the stone walls created by the first command.

fill ~-2 ~-1 ~-2 ~2 ~2 ~2 stonebrick 0 hollow fill ~-2 ~-1 ~-2 ~2 ~-1 ~2 planks fill ~ ~ ~2 ~ ~ ~2 wooden_door 1 fill ~-2 ~1 ~ ~-2 ~1 ~ glass fill ~2 ~1 ~ ~2 ~1 ~ glass fill ~ ~1 ~-2 ~ ~1 ~-2 glass

Running a function
Functions attempt to run all commands within a single tick, including the commands of nested functions called within another function.

Limits
A single function call runs up to 10,000 commands (including calls to other functions, i.e. recursion).


 * Allows players to run a function once
 * The commands in the function are run through the entity or command block that ran the  command.
 * Usage:

History
関数 (Bedrock Edition) 函数（基岩版）