Skip to content
WikilyWIKILY
All games23 Wikis · pick your game
Commands and cheatsAll commands

Switch game

23 Wikis · pick your game
/return

Command

/return

Stops a function early and sets the value the function returns.

Syntax

/return fail
/return run <command>
/return <value>

Arguments

ArgumentKind of valueWhat to type
<value>Whole numberThe whole number the function returns. Negative numbers and 0 are allowed.

Details

Permission level2: operators, worlds with cheats on, command blocks and functions
Works inSingleplayer with cheats enabled, operators on multiplayer servers, command blocks and functions. It is meant to be used inside functions.
ResultNo 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 functionCommands that come after /return in the same function are not run.
Using the valueThe returned value is what /execute store and /execute if function see when they call the function.
return runAny command can follow run, including /execute. The function ends and gives back that command's result.

Examples

/return 1

Ends the function with the result 1.

/return fail

Ends the function and marks it as failed.

/return run data get entity @s Health

Ends 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.

Join the creator communityThe people who build the Minecraft Java Edition wiki are on our Discord. Ask questions or suggest pages.Join Discord (opens Discord in a new tab)