Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Commands/function: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Remove broken links to missing pages
SyncBot (talk | contribs)
Fix template calls: add MC/ prefix
 
Line 10: Line 10:


== Usage ==
== Usage ==
{{IN|java}}, runs a function or all functions in a tag from a data pack.
{{MC/In|java}}, runs a function or all functions in a tag from a data pack.


{{IN|bedrock}}, runs a [[Minecraft:Function (Bedrock Edition)|function]] from a [[Minecraft:behavior pack]].
{{MC/In|bedrock}}, runs a [[Minecraft:Function (Bedrock Edition)|function]] from a [[Minecraft:behavior pack]].


{{IN|java}}, the behavior of {{cmd|return run function ...}} (or {{cmd|return run execute ... run function ...}}) is different with a direct call to the {{cmd|link=none|function}} command. If {{cmd|return run function ...}} runs multiple functions, execution stops after first {{cmd|link=none|return}} in any of the functions. If a direct call to the {{cmd|function ...|link=none}} runs multiple functions, all of the functions are executed, and the return values are added up as the <code>result</code> value of the {{cmd|function ...|link=none}} command.
{{MC/In|java}}, the behavior of {{MC/Cmd|return run function ...}} (or {{MC/Cmd|return run execute ... run function ...}}) is different with a direct call to the {{MC/Cmd|link=none|function}} command. If {{MC/Cmd|return run function ...}} runs multiple functions, execution stops after first {{MC/Cmd|link=none|return}} in any of the functions. If a direct call to the {{MC/Cmd|function ...|link=none}} runs multiple functions, all of the functions are executed, and the return values are added up as the <code>result</code> value of the {{MC/Cmd|function ...|link=none}} command.


== Syntax ==
== Syntax ==
Line 29: Line 29:


== Arguments ==
== Arguments ==
{{argument|name|function|name: filepath|CommandFilePath}}
{{MC/Argument|name|function|name: filepath|CommandFilePath}}
: Specifies the function(s) to execute.
: Specifies the function(s) to execute.
: {{arg desc|je=function|be=commandfilepath}}
: {{MC/Arg desc|je=function|be=commandfilepath}}


{{el|je|short=1}}: {{Argument|arguments|nbt_compound_tag}}
{{MC/El|je|short=1}}: {{MC/Argument|arguments|nbt_compound_tag}}
: Specifies arguments for macro functions in a compound NBT tag.
: Specifies arguments for macro functions in a compound NBT tag.
: {{Arg desc|je=nbt_compound_tag}}
: {{MC/Arg desc|je=nbt_compound_tag}}


{{el|je|short=1}}: {{Argument|sourcePos|block_pos}}
{{MC/El|je|short=1}}: {{MC/Argument|sourcePos|block_pos}}
: The position of the target [[Minecraft:block entity]] whose NBT is to be used.
: The position of the target [[Minecraft:block entity]] whose NBT is to be used.
: {{arg desc|je=block_pos}}
: {{MC/Arg desc|je=block_pos}}


{{el|je|short=1}}: {{Argument|source|entity}} (in <code>entity <target></code> mode)
{{MC/El|je|short=1}}: {{MC/Argument|source|entity}} (in <code>entity <target></code> mode)
: Specifies an entity whose NBT is to be used.
: Specifies an entity whose NBT is to be used.
: {{arg desc|je=entity|amount=single|type=entitie}}
: {{MC/Arg desc|je=entity|amount=single|type=entitie}}


{{el|je|short=1}}: {{Argument|source|resource_location}} (in <code>storage <target></code> mode)
{{MC/El|je|short=1}}: {{MC/Argument|source|resource_location}} (in <code>storage <target></code> mode)
: Specifies a storage whose NBT is to be used.
: Specifies a storage whose NBT is to be used.
: {{arg desc|je=resource_location}}
: {{MC/Arg desc|je=resource_location}}


{{el|je|short=1}}: {{Argument|path|nbt_path}}
{{MC/El|je|short=1}}: {{MC/Argument|path|nbt_path}}
: Specifies the NBT path. Should be a path of a single compound tag.
: Specifies the NBT path. Should be a path of a single compound tag.
: {{arg desc|je=nbt_path}}
: {{MC/Arg desc|je=nbt_path}}


== Result ==
== Result ==
Line 66: Line 66:
{{Result table|The tag at <code><path></code> is not a compound tag.}}
{{Result table|The tag at <code><path></code> is not a compound tag.}}
{{Result table|cmd=/... <arguments><br>/... with ..|With the provided arguments, any macro line in the function(s) becomes an unparseable command.}}
{{Result table|cmd=/... <arguments><br>/... with ..|With the provided arguments, any macro line in the function(s) becomes an unparseable command.}}
{{Result table|cmd=|Only one function is specified, and in it there's no {{cmd|return}} command being executed.|[[Minecraft:Commands#Result|Void]]}}
{{Result table|cmd=|Only one function is specified, and in it there's no {{MC/Cmd|return}} command being executed.|[[Minecraft:Commands#Result|Void]]}}
{{Result table|Only one function is specified, and in it there's a {{cmd|return}} command being executed and returning a failure.|fail}}
{{Result table|Only one function is specified, and in it there's a {{MC/Cmd|return}} command being executed and returning a failure.|fail}}
{{Result table|Multiple functions are specified, and in all of the functions, there is no {{cmd|return}} command being executed.|Void}}
{{Result table|Multiple functions are specified, and in all of the functions, there is no {{MC/Cmd|return}} command being executed.|Void}}
{{Result table|succeed}}
{{Result table|succeed}}
{{Result table}}
{{Result table}}


== Output ==
== Output ==
{{IN|java}}, for {{cmd|return run execute store ... run function ...}}:
{{MC/In|java}}, for {{MC/Cmd|return run execute store ... run function ...}}:
{{Output table}}
{{MC/Output table}}
{{Output table|edition=je|On fail|N/A|0|0}}
{{MC/Output table|edition=je|On fail|N/A|0|0}}
{{Output table|On void|N/A|unchanged|unchanged}}
{{MC/Output table|On void|N/A|unchanged|unchanged}}
{{Output table|On success|N/A|1|the return value of the first non-void function<br>(Execution stops after first {{cmd|link=none|return}} in any of the specified functions)}}
{{Output table|On success|N/A|1|the return value of the first non-void function<br>(Execution stops after first {{MC/Cmd|link=none|return}} in any of the specified functions)}}
{{Output table}}
{{MC/Output table}}
{{IN|java}}, otherwise:
{{MC/In|java}}, otherwise:
{{Output table}}
{{MC/Output table}}
{{Output table|edition=je|On fail|0|0|0}}
{{MC/Output table|edition=je|On fail|0|0|0}}
{{Output table|On void|0|unchanged|unchanged}}
{{MC/Output table|On void|0|unchanged|unchanged}}
{{Output table|On success|1|1|the sum of the return values of all the non-void functions}}
{{MC/Output table|On success|1|1|the sum of the return values of all the non-void functions}}
{{Output table}}
{{MC/Output table}}
{{IN|be}}:
{{MC/In|be}}:
{{Output table|onlybe=1}}
{{MC/Output table|onlybe=1}}
{{Output table|edition=be|On fail|0}}
{{MC/Output table|edition=be|On fail|0}}
{{Output table|On success|1}}
{{MC/Output table|On success|1}}
{{Output table}}
{{MC/Output table}}


== Examples ==
== Examples ==
* {{IN|java}}:  
* {{MC/In|java}}:  
** To run a function located at <code>data/custom/function/example/test.mcfunction</code> in a loaded data pack: {{cmd|function custom:example/test|link=none}}
** To run a function located at <code>data/custom/function/example/test.mcfunction</code> in a loaded data pack: {{MC/Cmd|function custom:example/test|link=none}}
** To run all functions in a function tag located at <code>data/custom/tags/function/example/test.json</code>: {{cmd|function #custom:example/test|link=none}}
** To run all functions in a function tag located at <code>data/custom/tags/function/example/test.json</code>: {{MC/Cmd|function #custom:example/test|link=none}}
** To run a function if there is a sheep within a radius of 2 blocks: <code>/execute if entity @e[type=sheep,distance=..2] run function custom:example/test</code>
** To run a function if there is a sheep within a radius of 2 blocks: <code>/execute if entity @e[type=sheep,distance=..2] run function custom:example/test</code>
** To run a function unless the executor is a player: <code>/execute unless entity @s[type=player] run function custom:example/test</code>
** To run a function unless the executor is a player: <code>/execute unless entity @s[type=player] run function custom:example/test</code>
Line 103: Line 103:
=== ''Java Edition'' ===
=== ''Java Edition'' ===
{{HistoryTable
{{HistoryTable
|{{HistoryLine|java}}
|{{MC/HistoryLine|java}}
|{{HistoryLine||1.12|dev=pre1|Added {{cmd|function|link=none}}.}}
|{{HistoryLine||1.12|dev=pre1|Added {{MC/Cmd|function|link=none}}.}}
|{{HistoryLine|||dev=pre4|Added new arguments to the {{cmd|function|link=none}} command: <code>[if{{!}}unless] [selector]</code>}}
|{{HistoryLine|||dev=pre4|Added new arguments to the {{MC/Cmd|function|link=none}} command: <code>[if{{!}}unless] [selector]</code>}}
|{{HistoryLine|||dev=pre6|Skipped functions (when a conditional fails) are now considered failures when used in commands.}}
|{{MC/HistoryLine|||dev=pre6|Skipped functions (when a conditional fails) are now considered failures when used in commands.}}
|{{HistoryLine||1.13|dev=17w49b|{{cmd|function|link=none}} now accept function tags as the argument.|Removed {{cd|[if{{!}}unless]}} arguments in favor of {{cmd|execute [if{{!}}unless]}}.}}
|{{HistoryLine||1.13|dev=17w49b|{{MC/Cmd|function|link=none}} now accept function tags as the argument.|Removed {{cd|[if{{!}}unless]}} arguments in favor of {{cmd|execute [if{{!}}unless]}}.}}
|{{HistoryLine||1.20.2|dev=23w31a|Added function macro arguments.}}
|{{MC/HistoryLine||1.20.2|dev=23w31a|Added function macro arguments.}}
|{{HistoryLine||1.20.3|dev=23w41a|{{cmd|link=none|function}} command no longer returns the number of commands executed to better accommodate new {{cmd|return}} command.}}
|{{HistoryLine||1.20.3|dev=23w41a|{{MC/Cmd|link=none|function}} command no longer returns the number of commands executed to better accommodate new {{MC/Cmd|return}} command.}}
|{{HistoryLine|||dev=23w44a|If {{cmd|link=none|function <''function tag''>}} runs multiple functions in combination with {{cmd|link=none|return run}}, execution stops after first {{cmd|link=none|return}} in any of the functions.|A single call to the {{cmd|link=none|function}} command always returns when run with {{cmd|link=none|return run}}. For example, {{cmd|link=none|return run execute ''[split context]'' run function ''<some function with conditional return>''}} always returns after processing the first context.}}
|{{HistoryLine|||dev=23w44a|If {{MC/Cmd|link=none|function <''function tag''>}} runs multiple functions in combination with {{MC/Cmd|link=none|return run}}, execution stops after first {{MC/Cmd|link=none|return}} in any of the functions.|A single call to the {{MC/Cmd|link=none|function}} command always returns when run with {{MC/Cmd|link=none|return run}}. For example, {{MC/Cmd|link=none|return run execute ''[split context]'' run function ''<some function with conditional return>''}} always returns after processing the first context.}}
|{{HistoryLine||1.20.5|dev=23w51a|Fixed a bug that <code>/function</code> executing a function with <code>/return fail</code> has a <code>success</code> value of 1.<ref>{{bug|MC-267193|||fixed}}</ref><ref>{{bug|MC-268160}}</ref>}}
|{{HistoryLine||1.20.5|dev=23w51a|Fixed a bug that <code>/function</code> executing a function with <code>/return fail</code> has a <code>success</code> value of 1.<ref>{{bug|MC-267193|||fixed}}</ref><ref>{{bug|MC-268160}}</ref>}}
}}
}}
Line 116: Line 116:
=== ''Bedrock Edition'' ===
=== ''Bedrock Edition'' ===
{{HistoryTable
{{HistoryTable
|{{HistoryLine|bedrock}}
|{{MC/HistoryLine|bedrock}}
|{{HistoryLine||1.8.0|dev=beta 1.8.0.8|Added {{cmd|function|link=none}}.}}
|{{HistoryLine||1.8.0|dev=beta 1.8.0.8|Added {{MC/Cmd|function|link=none}}.}}
}}
}}


== See also ==
== See also ==
* {{cmd|tag}} – To run function in batch, every tick, or on server (re)load.
* {{MC/Cmd|tag}} – To run function in batch, every tick, or on server (re)load.


== References ==
== References ==
{{Reflist}}
{{MC/Reflist}}


== External links ==
== External links ==
Line 130: Line 130:


== Navigation ==
== Navigation ==
{{Navbox commands}}
{{MC/Navbox commands}}


de:Befehl/function
de:Befehl/function

Latest revision as of 20:10, 9 April 2026

Template:Infobox command

Runs commands found in the corresponding function file(s) with command execution context (executor, execution position, angles, etc) of the /function command itself.

Usage

in Template:Editions, runs a function or all functions in a tag from a data pack.

in Template:Editions, runs a function from a Minecraft:behavior pack.

in Template:Editions, the behavior of

  1. REDIRECT Template:Command

Template:Redr (or

  1. REDIRECT Template:Command

Template:Redr) is different with a direct call to the

  1. REDIRECT Template:Command

Template:Redr command. If

  1. REDIRECT Template:Command

Template:Redr runs multiple functions, execution stops after first

  1. REDIRECT Template:Command

Template:Redr in any of the functions. If a direct call to the

  1. REDIRECT Template:Command

Template:Redr runs multiple functions, all of the functions are executed, and the return values are added up as the result value of the

  1. REDIRECT Template:Command

Template:Redr command.

Syntax

  • Java Edition
function <name>
Runs a function or functions in a tag.
function <name> <arguments>
function <name> with (block <sourcePos>|entity <source>|storage <source>) [<path>]
Runs a function or functions in a tag, with arguments for macros.
  • Bedrock Edition
function <name: filepath>
Runs a function.

Arguments

Template:El<name>: function
Template:El: name: filepath: CommandFilePath

Specifies the function(s) to execute.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|function}}{{#vardefine:be-arg|function}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
  1. REDIRECT Template:Edition

Template:Rcat: <arguments>: nbt_compound_tag

Specifies arguments for macro functions in a compound NBT tag.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_compound_tag}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
  1. REDIRECT Template:Edition

Template:Rcat: <sourcePos>: block_pos

The position of the target Minecraft:block entity whose NBT is to be used.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|block_pos}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
  1. REDIRECT Template:Edition

Template:Rcat: <source>: entity (in entity <target> mode)

Specifies an entity whose NBT is to be used.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
  1. REDIRECT Template:Edition

Template:Rcat: <source>: resource_location (in storage <target> mode)

Specifies a storage whose NBT is to be used.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_location}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
  1. REDIRECT Template:Edition

Template:Rcat: <path>: nbt_path

Specifies the NBT path. Should be a path of a single compound tag.
{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|nbt_path}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}

Result

Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table

Output

in Template:Editions, for

  1. REDIRECT Template:Command

Template:Redr:

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|N/A}}{{#vardefine:output2-{{#var:output-table-lines}}|0}}{{#vardefine:output3-{{#var:output-table-lines}}|0}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-editions-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-{{#var:output-editions-num}}|je}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|1}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On void}}{{#vardefine:output1-{{#var:output-table-lines}}|N/A}}{{#vardefine:output2-{{#var:output-table-lines}}|unchanged}}{{#vardefine:output3-{{#var:output-table-lines}}|unchanged}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}} Template:Output table

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}

in Template:Editions, otherwise:

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|0}}{{#vardefine:output3-{{#var:output-table-lines}}|0}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-editions-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-{{#var:output-editions-num}}|je}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|1}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On void}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|unchanged}}{{#vardefine:output3-{{#var:output-table-lines}}|unchanged}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|the sum of the return values of all the non-void functions}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}

in Template:Editions:

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-editions-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-{{#var:output-editions-num}}|be}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|1}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}

Examples

  • in Template:Editions:
    • To run a function located at data/custom/function/example/test.mcfunction in a loaded data pack:
  1. REDIRECT Template:Command

Template:Redr

    • To run all functions in a function tag located at data/custom/tags/function/example/test.json:
  1. REDIRECT Template:Command

Template:Redr

    • To run a function if there is a sheep within a radius of 2 blocks: /execute if entity @e[type=sheep,distance=..2] run function custom:example/test
    • To run a function unless the executor is a player: /execute unless entity @s[type=player] run function custom:example/test
    • To run a function macro with arguments a=42, b="example": /function custom:example/test {a: 42, b: "example"}
    • To run a function macro with arguments from storage custom:storage: /function custom:example/test with custom:storage

History

Java Edition

Template:HistoryTable

Bedrock Edition

Template:HistoryTable

See also

  1. REDIRECT Template:Command

Template:Redr – To run function in batch, every tick, or on server (re)load.

References

<references group="">

 </references>

External links

Navigation

All editions
Removed
Template:El only
Debug
Removed
Template:Els only
Template:El only
Removed
Template:El only
Removed
Template:Els only
Removed
Joke
Related

de:Befehl/function es:Comandos/function ja:コマンド/function ko:명령어/function pt:Comandos/function ru:Команды консоли/function uk:Команди консолі/function zh:命令/function