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/return

From SAS Gaming Wiki
Revision as of 20:13, 9 April 2026 by SyncBot (talk | contribs) (Fix template calls: add MC/ prefix)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Script error: No such module "Exclusive". Template:Infobox command A command that can be embedded inside a function to control its execution.

It ends function execution and sets the successfulness and the return value of the function, which is returned to the

  1. REDIRECT Template:Command

Template:Redr command as its output values, or the

  1. REDIRECT Template:Command

Template:Redr command to test.

It can also end a forking

  1. REDIRECT Template:Command

Template:Redr command that has multiple branches at the first branch.

Usage

By placing this command in a function, the function can be stopped at a certain line, and the return value and the successfulness of the function are set.

  • If the function is called by a
  1. REDIRECT Template:Command

Template:Redr command, the return value and successfulness are returned to the

  1. REDIRECT Template:Command

Template:Redr command as its output values, and then can be stored using

  1. REDIRECT Template:Command

Template:Redr.

  • If the function is called by a
  1. REDIRECT Template:Command

Template:Redr command, the return value is checked whether it is not 0.

Like other commands, following a Template:Cmd or a forking

  1. REDIRECT Template:Command

Template:Redr command that may terminate, this command can be restricted to only execute under certain conditions. With this, under different conditions a function can end at different lines, thus achieving more complex behaviors. For example, the following function simulates an if-else statement: <syntaxhighlight lang="mcfunction">

  1. if (@s[tag=test1]) then return function("test1")

execute if entity @s[tag=test1] run return run function test1

  1. else if (@s[type=player]) then return function("test2")

execute if entity @s[type=player] run return run function test2

  1. else return function("test3")

return run function test3 </syntaxhighlight>

Following a forking

  1. REDIRECT Template:Command

Template:Redr command that has multiple branches, the

  1. REDIRECT Template:Command

Template:Redr command also ends after the first execution of the

  1. REDIRECT Template:Command

Template:Redr command. So, only the first branch is executed. This can be used to ensure a command is executed only once. For example: /execute as @e[type=zombie,sort=nearest] at @s if block ~ ~-1 ~ grass_block run return run tp @s Steve teleports the nearest one zombie that is on a grass block to Steve, if such a zombie exists. Note this command in a function also ends the function.

Followed by a forking

  1. REDIRECT Template:Command

Template:Redr command that has multiple branches, the

  1. REDIRECT Template:Command

Template:Redr command also ends after the first branch execution.

The only difference between return run execute ... run <command> and execute ... run return run <command> is that in the first instance, the

  1. REDIRECT Template:Command

Template:Redr command always executes, and it returns a failure and a 0 value when the

  1. REDIRECT Template:Command

Template:Redr command terminates; While the

  1. REDIRECT Template:Command

Template:Redr command in the second instance does not execute when the

  1. REDIRECT Template:Command

Template:Redr command terminates.

Followed by a

  1. REDIRECT Template:Command

Template:Redr command that calls multiple functions in a tag, the whole

  1. REDIRECT Template:Command

Template:Redr command also ends after the first execution of the

  1. REDIRECT Template:Command

Template:Redr command in any of the functions. See also the

  1. REDIRECT Template:Command

Template:Redr article.

The

  1. REDIRECT Template:Command

Template:Redr command sets the return value and the successfulness of a function if it is executed in the function. They are returned to the

  1. REDIRECT Template:Command

Template:Redr or the

  1. REDIRECT Template:Command

Template:Redr command that is calling the function. However, the

  1. REDIRECT Template:Command

Template:Redr command itself also has its output values. Following a

  1. REDIRECT Template:Command

Template:Redr command, its success value and result value of the

  1. REDIRECT Template:Command

Template:Redr command can be stored while it ends the

  1. REDIRECT Template:Command

Template:Redr command and the function. Directly executed in a command block, the success count of the

  1. REDIRECT Template:Command

Template:Redr command is recorded by the command block.

Syntax

return <value>

Ends the function to which it belongs with a success, and sets the return value of the function to the specified integer value.

return fail

Ends the function with a failure and a return value of 0.

return run <command>

Executes the command specified in <command>, ends the function to which it belongs, and sets the successfulness and return value of the function to the success value and result value of that command. If the command is a forking
  1. REDIRECT Template:Command

Template:Redr, only the first branch is executed.

Arguments

<value>: integer

An integer value to use as the return value of the
  1. REDIRECT Template:Code

Template:Redr.

{{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|integer}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}

<command>

A command to execute.

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

Output

{{#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|}}

Template:Output table {{#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:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/return fail}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#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 fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|0}}{{#vardefine:output3-{{#var:output-table-lines}}|0}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/return run <command>}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#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|}}

Above are the outputs of the

  1. REDIRECT Template:Command

Template:Redr command itself. And the successfulness and the return value of the function are also set if the

  1. REDIRECT Template:Command

Template:Redr command is executed in a function. The successfulness of the function equals to the success value of the

  1. REDIRECT Template:Command

Template:Redr command. The return value of the function equals to the result value of the

  1. REDIRECT Template:Command

Template:Redr command.

History

Template:HistoryTable

References

<references/>

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/return ja:コマンド/return lzh:令/return pt:Comandos/return zh:命令/return