
Command
/return
Stops a function early and sets the value the function returns.
| /return fail |
| /return run <command> |
| /return <value> |
| Argument | Kind of value | What to type |
|---|---|---|
| <value> | Whole number | The whole number the function returns. Negative numbers and 0 are allowed. |
| Permission level | 2: operators, worlds with cheats on, command blocks and functions |
| Works in | Singleplayer with cheats enabled, operators on multiplayer servers, command blocks and functions. It is meant to be used inside functions. |
| Result | No chat message. /return <value> makes the function succeed with that number as its result. /return fail makes the function fail, which counts as result 0 and no success. /return run makes the function return the result of the command that follows. |
| Stops the function | Commands that come after /return in the same function are not run. |
| Using the value | The returned value is what /execute store and /execute if function see when they call the function. |
| return run | Any command can follow run, including /execute. The function ends and gives back that command's result. |
/return 1Ends the function with the result 1.
/return failEnds the function and marks it as failed.
/return run data get entity @s HealthEnds the function and returns the health of the entity running it.
/return run execute if entity @e[type=minecraft:creeper,distance=..10]Ends the function and returns how many Creepers are within 10 blocks.

