Skip to content

Execute Run and Execute If Else

SnaveSutit edited this page Dec 2, 2023 · 1 revision

Execute Run blocks create a new function that gets called with the execute command's context.

function execute_run {
    execute if score a b matches 1 run {
        say hi!
    }
    # Any execute subcommands function as expected
    execute align xyz positioned ~.5 ~ ~.5 run {
        say I'm aligned in the center of a block!
    }
}

Any execute run block can be turned into an execute if / else block by appending an else execute or else block to it like so:

function if_else {
    execute if score a b matches 1 run {
        say 1
    } else {
        say not 1
    }

    execute if score a b matches 1 run {
        say 1
    } else execute if score a b matches 2 run {
        say 2
    } else {
        say not 1 or 2
    }
}
Clone this wiki locally