Skip to content
/SLASHPLAY

How to return a value from a function in Minecraft

Put return 1 in a function to stop it there with 1 as its result, or return fail to end it as failed. Read it with execute store.

return

Ends the current function early and returns a value, a failure, or the result of another command.

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

Examples

/return 1

Ends the function with result 1.

/return fail

Ends the function as a failure.

/return run scoreboard players get @s points

Returns the player's score.

Arguments

valueOptional
Integer result.
commandOptional
Command whose result is returned, after run.

What it does

Used inside functions: return <value> stops the function with that number as its result, return fail stops it as failed, and return run <command> returns the result of a command. The returned value can be read with execute store or checked with execute if function.

Good to know

  • Needs operator permission level 2.
  • In a .mcfunction file, write it without the slash.

Run it on your server

On a SLASHPLAY server, type it in the Console tab without the leading slash; in game, operators type it in chat with the slash. New to this? Start a Minecraft server first.

Your own
Minecraft server.

From $0.03 an hour, only while it runs. New accounts get 6 free tokens.