Execute and Return run
Any execute ... run command can be followed by a Block to create a new function that gets called by execute command.
execute ... run {
<...>
}
Examples
Conditional Execution
execute if score @s appleCount matches 1 run {
say I have 1 apple!
}
Return Run
return run can also be followed by a Block. Like other blocks, it can take macro arguments after the opening bracket.
return run {
<...>
}
Examples
Returning the Result of a Block
function check {
return run {
execute if entity @s[tag=ready] run return 1
return 0
}
}
return run function my_pack:zzz/0
Execute If / Else
Any execute run block can be turned into an execute if / else block by appending an else execute ... run or else run block to it
execute ... run {
<...>
} else execute ... run {
<...>
} else run {
<...>
}
Examples
Multi-Conditional Execution
execute if score @s appleCount matches ..0 run {
say I have no apples!
} else execute if score @s appleCount matches 1 run {
say I have 1 apple!
} else run {
say I have more than 1 apple!
}
Execute If / Unless Function
You can embed a Block in the if/unless function execute sub-command. Write if or unless followed directly by the block. MC-Build adds the function keyword when it generates the call.
execute <if|unless> {
<...>
} run <...>
The rest of the execute command goes on the same line as the closing bracket. It can be any execute chain, including another embedded block or a run block.
execute if {
<...>
} if {
<...>
} as @a run {
<...>
}
Examples
If Function
An OR condition using if function
function a {
execute if {
execute if score @s test matches 1 run return 1
execute if score @s test matches 5 run return 1
execute if score @s test matches 10 run return 1
return 0
} run say "Hello World!"
}
execute if function example:zzz/0 run say "Hello World!"
execute if score @s test matches 1 run return 1
execute if score @s test matches 5 run return 1
execute if score @s test matches 10 run return 1
return 0