Minecraft:Function (Bedrock Edition): Difference between revisions
More actions
Remove broken links to missing pages |
Fix template calls: add MC/ prefix |
||
| Line 1: | Line 1: | ||
{{about|functions {{ | {{about|functions {{MC/In|BE}}|the corresponding feature {{MC/In|JE}}|Function (Java Edition)|other uses|Function}} | ||
'''Functions''' allow players to run lists of commands using text files with the extension <code>.mcfunction</code>. This page covers how to use functions {{ | '''Functions''' allow players to run lists of commands using text files with the extension <code>.mcfunction</code>. This page covers how to use functions {{MC/In|BE}}. | ||
== Usage == | == Usage == | ||
Text files must be placed into a top-level folder named "functions" within a [[Minecraft:behavior pack]], located at {{mono|behavior_packs/[''behavior_pack'']/functions}}. Subfolders can also be added to this folder. For example, running the function <code>sub/foo</code> runs the file located at {{mono|[''behavior_pack'']/functions/sub/foo.mcfunction}}. | Text files must be placed into a top-level folder named "functions" within a [[Minecraft:behavior pack]], located at {{mono|behavior_packs/[''behavior_pack'']/functions}}. Subfolders can also be added to this folder. For example, running the function <code>sub/foo</code> runs the file located at {{mono|[''behavior_pack'']/functions/sub/foo.mcfunction}}. | ||
=== {{ | === {{MC/Cmd|reload}} === | ||
'''Note:''' Currently {{ | '''Note:''' Currently {{MC/Cmd|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. | ||
=== Success results === | === Success results === | ||
| Line 14: | Line 14: | ||
Within the <code>.mcfunction</code> file, one valid command is placed per line, without the usual forward slash <code>/</code>. Players can add comments within the function text file by preceding them with a <code>#</code>. | Within the <code>.mcfunction</code> file, one valid command is placed per line, without the usual forward slash <code>/</code>. Players can add comments within the function text file by preceding them with a <code>#</code>. | ||
=== {{ | === {{MC/Cd|min_engine_version}} === | ||
Functions require a minimum engine version specified in the pack {{ | Functions require a minimum engine version specified in the pack {{MC/Cd|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, {{ | This field determines which version of a command to run. The number specified here should match the version number of the game. For example, {{MC/Cmd|fill}} was changed in <code>[[Minecraft:Bedrock Edition 1.19.70|1.19.70]]</code>. If your behavior pack has <code>"min_engine_version": [1, 19, 10]</code> and runs a function that contains {{MC/Cmd|fill}}, it runs the older version of fill (as if the version was still <code>[[Minecraft:Bedrock Edition 1.19.10|1.19.10]]</code>). | ||
==== Manifest example ==== | ==== Manifest example ==== | ||
| Line 67: | Line 67: | ||
=== Commands === | === Commands === | ||
==== {{ | ==== {{MC/Cmd|function}} ==== | ||
* Allows players to run a function once. | * Allows players to run a function once. | ||
* The commands in the function are run through the entity or command block that ran the <code>/function</code> command. | * The commands in the function are run through the entity or command block that ran the <code>/function</code> command. | ||
| Line 74: | Line 74: | ||
<div class="treeview"> | <div class="treeview"> | ||
==== Command syntax ==== | ==== Command syntax ==== | ||
*{{ | *{{MC/Nbt|compound}} The root object. | ||
**{{ | **{{MC/Nbt|list|values}}: A list of functions. | ||
***{{ | ***{{MC/Nbt|string}}: A function. | ||
=== tick.json === | === tick.json === | ||
| Line 84: | Line 84: | ||
== History == | == History == | ||
{{HistoryTable | {{HistoryTable | ||
|{{HistoryLine|bedrock}} | |{{MC/HistoryLine|bedrock}} | ||
|{{HistoryLine||1.8.0|dev=beta 1.8.0.8|Added function files.|Function files are available only in behavior packs.}} | |{{MC/HistoryLine||1.8.0|dev=beta 1.8.0.8|Added function files.|Function files are available only in behavior packs.}} | ||
|{{HistoryLine||1.13.0|dev=beta 1.13.0.1|Function files are now visible in command list.}} | |{{MC/HistoryLine||1.13.0|dev=beta 1.13.0.1|Function files are now visible in command list.}} | ||
}} | }} | ||
== Navigation == | == Navigation == | ||
{{Navbox Bedrock Edition}} | {{MC/Navbox Bedrock Edition}} | ||
ja:関数 (Bedrock Edition) | ja:関数 (Bedrock Edition) | ||
Revision as of 20:25, 9 April 2026
|
For the {{{Description}}} of the same name, see [[{{{Destination}}}]]. |
Functions allow players to run lists of commands using text files with the extension .mcfunction. This page covers how to use functions in Template:Editions.
Usage
Text files must be placed into a top-level folder named "functions" within a Minecraft:behavior pack, located at Template:Mono. Subfolders can also be added to this folder. For example, running the function sub/foo runs the file located at Template:Mono.
===
- REDIRECT Template:Command
Template:Redr === Note: Currently
- REDIRECT Template:Command
Template:Redr 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: "Successfully executed Template:Mono function entries."
Function syntax
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 #.
===
- REDIRECT Template:Code
Template:Redr === Functions require a minimum engine version specified in the pack
- REDIRECT Template:Code
Template:Redr 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,
- REDIRECT Template:Command
Template:Redr was changed in 1.19.70. If your behavior pack has "min_engine_version": [1, 19, 10] and runs a function that contains
- REDIRECT Template:Command
Template:Redr, it runs the older version of fill (as if the version was still 1.19.10).
Manifest example
A manifest is required for Add-Ons, behaviour packs and resource packs to work. Note that the three dots ... must be replaced with an actual UUID, which can be generated with a UUID generator like UUIDTools.com.
{
"format_version": 3,
"header": {
"name": "House Building Add-On",
"description": "Let the game build houses for you using this Add-On",
"uuid": "...",
"version": "1.0.0",
"min_engine_version": "1.26.10"
},
"modules": [
{
"type": "data",
"uuid": "...",
"version": "1.0.0"
}
],
"metadata": {
"authors": ["Minecraft Wiki"],
"product_type": "addon"
}
}
Simple function example
title @p title Test setblock ~ ~2 ~ sulfur_bricks say Test #this is a comment
More complex function example
This function builds a basic house around the executor. Note that because the function runs commands in order, the Minecraft:glass windows and spruce door replace the walls created by the first command.
fill ~-2 ~-1 ~-2 ~2 ~2 ~2 stone_bricks 0 hollow fill ~-2 ~-1 ~-2 ~2 ~-1 ~2 spruce_planks fill ~ ~ ~2 ~ ~ ~2 spruce_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).
Commands
====
- REDIRECT Template:Command
Template:Redr ====
- Allows players to run a function once.
- The commands in the function are run through the entity or command block that ran the
/functioncommand. - Syntax:
/function <path/to/function/file>
Command syntax
- Template:Nbt/sprite The root object.
- Template:Nbt/sprite values: A list of functions.
- Template:Nbt/sprite: A function.
- Template:Nbt/sprite values: A list of functions.
tick.json
- The tick.json file is also located in the Template:Mono folder, specifying functions to be executed on every game tick. Functions running in this file are executed by the server at origin 0, 0, 0 in the overworld. Functions in this file are executed as soon as the world is initialized, regardless of whether or not the player has been loaded.
History
ja:関数 (Bedrock Edition) pt:Funções (Edição Bedrock) uk:Функція (Bedrock Edition) zh:基岩版函数