Minecraft:Commands/return
More actions
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
- REDIRECT Template:Command
Template:Redr command as its output values, or the
- REDIRECT Template:Command
Template:Redr command to test.
It can also end a forking
- 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
- REDIRECT Template:Command
Template:Redr command, the return value and successfulness are returned to the
- REDIRECT Template:Command
Template:Redr command as its output values, and then can be stored using
- REDIRECT Template:Command
- If the function is called by a
- 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
- 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">
- if (@s[tag=test1]) then return function("test1")
execute if entity @s[tag=test1] run return run function test1
- else if (@s[type=player]) then return function("test2")
execute if entity @s[type=player] run return run function test2
- else return function("test3")
return run function test3 </syntaxhighlight>
Following a forking
- REDIRECT Template:Command
Template:Redr command that has multiple branches, the
- REDIRECT Template:Command
Template:Redr command also ends after the first execution of the
- 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
- REDIRECT Template:Command
Template:Redr command that has multiple branches, the
- 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
- REDIRECT Template:Command
Template:Redr command always executes, and it returns a failure and a 0 value when the
- REDIRECT Template:Command
Template:Redr command terminates; While the
- REDIRECT Template:Command
Template:Redr command in the second instance does not execute when the
- REDIRECT Template:Command
Template:Redr command terminates.
Followed by a
- REDIRECT Template:Command
Template:Redr command that calls multiple functions in a tag, the whole
- REDIRECT Template:Command
Template:Redr command also ends after the first execution of the
- REDIRECT Template:Command
Template:Redr command in any of the functions. See also the
- REDIRECT Template:Command
Template:Redr article.
The
- 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
- REDIRECT Template:Command
Template:Redr or the
- REDIRECT Template:Command
Template:Redr command that is calling the function. However, the
- REDIRECT Template:Command
Template:Redr command itself also has its output values. Following a
- REDIRECT Template:Command
Template:Redr command, its success value and result value of the
- REDIRECT Template:Command
Template:Redr command can be stored while it ends the
- REDIRECT Template:Command
Template:Redr command and the function. Directly executed in a command block, the success count of the
- 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 thesuccessvalue andresultvalue of that command. If the command is a forking
- 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
- REDIRECT Template:Code
- {{#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
- REDIRECT Template:Command
Template:Redr command itself. And the successfulness and the return value of the function are also set if the
- REDIRECT Template:Command
Template:Redr command is executed in a function. The successfulness of the function equals to the success value of the
- REDIRECT Template:Command
Template:Redr command. The return value of the function equals to the result value of the
- REDIRECT Template:Command
Template:Redr command.
History
References
<references/>
de:Befehl/return ja:コマンド/return lzh:令/return pt:Comandos/return zh:命令/return