A command that can be embedded inside a function to control the execution of the function. Terminate the execution of the function and set the return value of the invoked function to an arbitrary integer value. By setting the return value to an arbitrary value, it can be used to record the execution results of /function commands with conditional branches and reflect them in subsequent function executions.
Usage
By placing this command at the end of a function , especially a function with a conditional branch. You can terminate the function and record which branch the function followed as a return value. The return value can be recorded using The recorded return value can be referenced. And can be reflected in the execution of other commands and functions.
Syntax
/return <value>
Terminate the function to which it belongs and /function set the return value of the command to an arbitrary integer value.
/return run <command>[upcoming: JE 1.20.2]
Executes the command specified in , terminates the function /function to which it belongs, and uses the return value of that command as the return value of the command that executed that function. If the executed command fails, the return value will be 0.
Arguments
<Value>
An integer value to set to the return value of the command that invoked the function to which this command belongs. Function
specify with a 32-bit integer value. Also, specify a value between -2,147,483,648 and 2,147,483,647.
<Command>
A command that gives the return value of the command that invoked the function to which this command belongs.
Result
| Command | Trigger | Java Edition |
|---|---|---|
| any | Incorrectly Specified Arguments | Unparseable |
return <value> | valueis outside the allowed range (-2147483648 to 2147483647) or is not an intege | Failed |
return run <command> | <command>command in fails | Failed |
| any | Otherwise | Stops execution of the function to which it belongs and gives the specified return value /function to |
Output
Originally /function a command that gives a return value to /return <value> but also the return value of the command itself . /return run ... There is no return value for either command itself.
| Command | Edition | Situation | Success Count | /execute store success ... | /execute store result ... |
|---|---|---|---|---|---|
return <value> | Java Edition | when successful | 1 | 1 | Return valueThe value of the. |
History
| Java Edition | |||||
|---|---|---|---|---|---|
| 1.20 | 23w16a | Added return. | |||
| 1.20.2 | 23w31a | Added a new subcommand run to return. | |||