DatapackJava

/return

Stops the current function immediately and sets its return value, which the calling /execute or /function can capture. /return run lets you return the result of another command. Added in 1.20 — brings early-exit and value-returning control flow to datapack functions.

What is /return used for?

What /return is for

Stops the current function immediately and sets its return value, which the calling /execute or /function can capture. Added in 1.20.

When to use /return

Add early-exit and value-returning control flow to datapack functions; /return run returns the result of another command.

Syntax

Parameters

value
integer
Value to return from the function.
commandoptional
command
Run a command and return its result (for run).

Examples

  • Exit the function now, returning 1 (success).

  • Return the executor's health value.

Permission level

/return requires Cheats (op level 2). In single-player you need the world's "Allow Cheats" toggle on. On a multiplayer server you need to be opped — see /op.