Functions
Introduction β
Sourced by the Bedrock Commands Community (BCC) Discord
Functions are .mcfunction files which contain multiple lines of commands. They are run with the /function command in-game.
Functions are created in a Behavior Pack, nested within the functions folder. A function pack creates a system using solely function files.
Functions are useful in many ways to reduce the time spent going from command block to command block debugging a system. They also help with packaging systems for use in multiple worlds and provide many functions that can change how everything works.
Function Pack Folder Structure β
- this_code.mcfunction
- more_of_this_code.mcfunction
- tick.json
- this_code_is_nested.mcfunction
To help create a consistent format, make it easier for everyone to follow, and to maintain uniformity across your functions, it is advised to follow these best-practices for your folder structure:
- All your
.mcfunctionfiles must be go in a namespaced root-folder within the functions folder. On Bedrock Wiki, we use thewikinamespace. However, you may choose a namespace based on your name or project. For more info, refer to the namespaces page.- β
οΈ
BP/functions/wiki/random_number.mcfunction - βοΈ
BP/functions/random_number.mcfunction
- β
οΈ
- Folders and files in a pack must be named using
snake_case- This means only lowercase alpha-numeric characters and underscores (
_) are allowed. - β
οΈ
BP/functions/wiki/scoreboard/objectives/add_all.mcfunction - βοΈ
BP/functions/wiki/scoreboard/objectives/Add-All.mcfunction
- This means only lowercase alpha-numeric characters and underscores (
- They must be properly nested:
- β
οΈ
BP/functions/wiki/teleport/zone/hell - β
BP/functions/wiki/teleport_hellzone
- β
οΈ
- The names must follow an
action_objectstructure. Meaning verbs should come before subjects.- β
οΈ
add_all - βοΈ
all_add - β
οΈ
shuffle_position - βοΈ
position_shuffle
- β
οΈ
- The total character length of any path must not exceed 80 characters (console limitation).
- Content folders should use consistent pluralization: Stick with names that are either all plural or all singular, don't mix and match. Example:
β οΈ Consistent:
BP/functions/wiki/ability/ice_blast.mcfunction
BP/functions/wiki/ability/fire_trail.mcfunction
BP/functions/wiki/event/players/on_death.mcfunction
BP/functions/wiki/event/worlds/on_initialize.mcfunction- All content folders
abilityandeventare consistently singular. - The content folders in
eventare also consistent, as bothplayersandworldsare plural.
βοΈ Inconsistent:
BP/functions/wiki/abilities/ice_blast.mcfunction
BP/functions/wiki/abilities/fire_trail.mcfunction
BP/functions/wiki/event/players/on_death.mcfunction
BP/functions/wiki/event/world/on_initialize.mcfunction- Only
abilitiescontent folder is pluralized whileeventis singular. - Also, in the
eventfolder, theplayersfolder is plural whileworldis singular.
Notes For Beginners β
Below is an example function file for beginners reference:
# These effects are for the spawn
effect @a[tag=wiki:at_spawn] regeneration 12 255 true
effect @a[tag=wiki:at_spawn] saturation 12 255 true
effect @a[tag=wiki:at_spawn] weakness 12 255 true
# These effects are for the nether
effect @a[tag=wiki:in_nether] fire_resistance 12 255 trueCommands in a function may not begin with a slash (
/). Each new line in a function file represents a new command (ignored if left blank). You may start a line with a hashtag (#) to add comments β the space after#is only a format preference. For comments style guide for functions, see the section below.All commands in a function are run in the same tick. Because of this, a function which causes large changes may cause a sudden lag spike and it is helpful to delegate some commands across multiple ticks, if possible. Commands in a function are still run in the same sequence, however.
In Minecraft Bedrock, functions cannot run more than 10,000 commands in a function file. This includes any other function files that are executed inside of the original file.
It is not possible to run conditional commands. Those will still need to utilize command blocks in some way, or could utilize the 1.19.50 execute syntax.
Running commands with a specified delay in a function involves using scoreboard timers to incrementally count up each tick until a certain point, and executing commands at specific scores within the file. See Scoreboard Timers page to learn it's setup.
Comments Style Guide β
- When working with functions that contain many commands, it's helpful to keep them organized by using multiple hashtags in comments to indicate different header levels.
- Optionally, to further distinguish these levels, you can apply different styles:
- level 1 headers - # UPPERCASE
- level 2 headers - ## Title Case
- level 3 headers - ### Sentence case
- Try to avoid the use of more than three header levels or too many headers overall, as this can make the code look cluttered. For your reference, see the example file below:
Example Function File
# ON PLAYER ITEM DROP
## Give Effects
### Fire resistance
execute at @e[type=item,name="Fire Trail Ability"] run effect @p[r=3] fire_resistance 10 255
### Speed
execute at @e[type=item,name="Fire Trail Ability"] run effect @p[r=3] speed 10 1 true
## Add Particle Time (10s)
execute at @e[type=item,name="Fire Trail Ability"] run scoreboard players set @p[r=3] abilities.fire_trail 200
## Delete Item
kill @e[type=item,name="Fire Trail Ability"]
# ENTITY TIMER
## Emit Particle Trail
execute at @a[scores={wiki:ability.fire_trail=1..}] run particle minecraft:basic_flame_particle ~~~
## Countdown Timer
scoreboard players remove @a [scores={wiki:ability.fire_trail=1..}] wiki:ability.fire_trail 1Note the use of two lines of spacing before level 1 headers and one line of spacing before level 2 headers for improved readability.
This practice helps create a consistent format, making it easier for everyone to follow, and maintain uniformity across your functions. For Scoreboard and Tags convention, see the Style Guide page.
Creating a Function β
Locate the
π com.mojangfolder and navigate toπ development_behavior_packs- The development folders are used for quick reloading of packs, as the packs aren't cached to the world files.
Create a folder (of any name) for the function pack. This will be referred to as Behavior Pack or BP.
Create a
π manifest.jsonfile and aπΌ pack_icon.pngfile (optional) within the BP folder.- A manifest file contains all the information needed to register a pack, while a pack icon displays visually in the pack menu. A pack icon is typically a 128x128 or a 256x256 image, though any power-of-2 resolution will do, they will be upscaled and downscaled accordingly.
Sample π manifest.json
{
"format_version": 2,
"header": {
"description": "Write Your Pack Description Here",
"name": "Write Your Pack Name Here",
"uuid": "00000000-0000-0000-0000-000000000000",
"version": [1, 0, 0],
"min_engine_version": [1, 19, 73]
},
"modules": [
{
"description": "Β§r",
"type": "data",
"uuid": "00000000-0000-0000-0000-000000000000",
"version": [1, 0, 0]
}
]
}Note that the uuid field needs to be replaced with an actual uuid, and the two generated must be different from one another. You can generate a uuid at uuidgenerator.net
Sample πΌ pack_icon.png
Sample A:
![]()
Sample B:
![]()
Create a
π functionsfolder. Any file within this folder that ends with .mcfunction will be registered as a function in-game, which can be run with/function <function_name>.- Nested functions are allowed, simply list the file path in relation to the functions folder as shown in the function pack folder structure.
Apply the behavior pack in-game and try out the functions. Function file changes can be reflected in the world by running
/reloador by simply relogging.
NOTE:
Functions are versioned; therefore, they will run in the version listed in the π manifest.json, such as:
min_engine_version1.19.50 or above will adopt the new execute syntax.min_engine_version1.19.70 or above will require aux values be replaced with block states.
Execution β
Functions can be executed in-game by typing /function name_of_function. This will execute all the commands in the function file, all in a single tick.
Nested functions, for example BP/functions/wiki/teleport/zone/hell can be run using the nested folder path, in this case /function wiki/teleport/zone/hell
Tick JSON β
The final file within a functions folder is the tick.json file. This specifies functions to run server-side on every game tick, (similar to a repeating command block). It is located in the BP/functions folder. By default, functions running in this file execute at origin (0, 0, 0) in the overworld. Example tick.json` file:
{
"values": [
"wiki/function_1",
"wiki/function_2"
]
}Note: Functions in this file are run as soon as the world is initialized, regardless of whether or not the player has been loaded. This may cause unintended behavior if used incorrectly.
Sample Function Pack β
Troubleshooting Functions β
Your functions may not appear within the command suggestions when using /function. This is normally due to an error with one or more commands in the function.
Enabling the Content Log in the creator settings allows you to see if there are any errors in your function pack, which function the error is in, on which line, and exactly what the syntax error is for that command.
The list of errors will be generated every time you load a world or run /reload to reflect changes after editing files. The list can be viewed on-screen for a few seconds, as well as in the content log history in settings.


Professional Workspace Setup (Optional) β
Setting up a dedicated workspace is the final step in developing function packs or add-ons like a pro. While you can write functions in a basic text editor, the following tools will help you catch errors instantly, collaborate with others, and sync your changes directly into Minecraft.
1. Visual Studio Code (VS Code) β
Think of VS Code as your command center. It is a powerful, free code editor that makes writing .mcfunction files much easier than using Notepad.
- Download: Get it from the Official VS Code Site.
- The Essential Plugin: Once installed, click the Extensions icon (the four squares) on the left sidebar and search for MCBE Command Checker.
- Why use it?
- Syntax Highlighting: Commands change color based on their type, making them easier to read.
- Auto-Complete: As you type, the editor will suggest valid arguments, targets, and block names.
- Error Detection: It will highlight typos or invalid syntax with a red underline before you even open the game.
Example screenshot:

2. Version Control with GitHub β
GitHub is a cloud-based service that acts as a "save point" for your projects.
- Create an Account: Sign up at GitHub.com.
- The Benefits:
- Cloud Backup: Youβll never lose your work if your computer crashes.
- Collaboration: You can share a link to your code so others can review it or help you fix bugs without sending files back and forth.
- History: You can see exactly what changes you made today versus a week ago.
- Releases: Once your pack is ready for the public, you can create a "Release." This allows you to host specific versions (like v1.0 or v2.1) as downloadable
.mcpackfiles, making it easy for players to find the most stable version of your work.
3. GitHub Desktop β
While GitHub lives in the cloud, GitHub Desktop is the app on your computer that talks to it. Itβs the easiest way for beginners to manage their files without learning complex "Git" commands.
- Download: Get it at desktop.github.com.
- The Workflow: After you finish writing code in VS Code, you use GitHub Desktop to "Commit" (save) and "Push" (upload) your changes to the cloud.
4. Linking Your Folders β
The biggest hurdle in Bedrock development is moving files from your "Work" folder to the Minecraft "Behavior Pack" folder. You can skip this manual step by creating a Directory Junction (a shortcut that acts like a real folder).
By linking your \GitHub\ProjectName folder to Minecraft's \development_behavior_packs\ProjectName folder, any change you save in VS Code is instantly updated in your Minecraft files.
How to Link Folders (Windows):
- Locate your project in your GitHub folder.
Example:
C:\Github\YOUR_PROJECT_NAME
- Locate your Minecraft development folder.
Example:
C:\Users\YOUR_NAME\AppData\Roaming\Minecraft Bedrock\Users\Shared\games\com.mojang\development_behavior_packs\YOUR_PROJECT_NAME
- Open Command Prompt as Administrator.
- Use the
mklink /Jcommand to link them.
Example:
mklink /J "Path\To\Minecraft\Folder" "Path\To\GitHub\Folder"`
TIP
Once these folders are linked, you donβt need to restart Minecraft or even re-enter the world to test your work. Simply save your file in VS Code and run the /reload command in-game to apply your changes immediately.
Bonus Tip: Enable Auto Save in VS Code (File > Auto Save) to make this process even fasterβjust tab back into Minecraft and run /reload!




