Function (Bedrock Edition)

From Minecraft Wiki
(Redirected from Function (Bedrock))
Jump to: navigation, search
Information icon.svg
This feature is exclusive to Bedrock Edition.
Arrow right.png
It has been suggested that this page be moved to Bedrock Edition function(s). Do not move the page until a consensus is reached. Discuss
Reason: Consistency with other articles that have a Java and bedrock variant; plural should be discussed
When moving, be sure to use the appropriate tool instead of simply copying and pasting the page's contents, to preserve edit history.

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

Usage[edit]

Text files must be placed into a top-level folder named "functions" within a behavior pack: [behavior_pack]/functions

Subfolders and namespacing[edit]

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

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

/reload[edit]

Note: Currently /reload 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. This may change in future updates of Minecraft.

Success results:[edit]

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[edit]

Within the .mcfunction 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 #.

min_engine_version[edit]

Functions require a minimum engine version specified in the pack manifest.json 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 /fill was changed in 1.9.0. If your behavior pack has "min_engine_version": [1, 8, 0] and runs a function that contains /fill, it runs the older version of fill (as if the version was still 1.8.0).

Manifest example[edit]

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

Simple function example[edit]

test.mcfunction

title @p title Test
setblock ~ ~2 ~ diamond_ore
say Test
#this is a comment

More complex function example[edit]

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[edit]

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

Limits[edit]

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

Commands[edit]

/function[edit]

  • Allows players to run a function once
  • The commands in the function are run through the entity or command block that ran the /function command.
  • Usage: /function <path/to/function/file>

History[edit]

Bedrock Edition
1.8.0?Added function files.
Function files are available only in behavior packs.
1.13.0beta 1.13.0.1Function files are now visible in command list.