Function Calls

MC-Build supports a few non-standard ways to reference functions. A function call can use a relative path, a hierarchical reference, a root reference, or a normal namespaced function reference.

Warning

Every function reference must start with a namespace (my_pack:) or one of the prefixes on this page (./, ../, * or ^). A bare name such as function my_function is a compile error. Use function ./my_function to call a function in the same folder.

These references also work in schedule commands and in function tags.

The hierarchical function reference starts with ^ and takes a number of steps up from the current function in which it's used.

function ^<integer>
Example
Code
function dummy {
    block {
        function ^1
        function ^0
    }
}
my_pack:zzz/0.mcfunction
function my_pack:dummy
function my_pack:zzz/0

The root function reference starts with * and will make a reference from current namespace with the given path.

function *<path>

Example
Code
dir folder {
    function dummy {
        function *dummy2
    }
}
function dummy2 {
    say Hello, world!
}
folder/dummy.mcfunction
function my_pack:dummy2

The relative function reference starts with either ./ or ../ and can be used to call a function relative to the call location. Similar to how file paths work in a file system.

function ./<path>
function ../<path>
Example
Code
dir folder {
    function dummy {
        function ./dummy2
        function ../dummy3
    }
    function dummy2 {
        say Hello, world!
    }
}
function dummy3 {
    say Hello, world!
}
folder/dummy.mcfunction
function my_pack:folder/dummy2
function my_pack:dummy3

The final way of calling a function is a normal namespaced function call.

function <path>
Example
Code
dir folder {
    function dummy {
        function my_pack:folder/dummy2
    }
    function dummy2 {
        say Hello, world!
    }
}
folder/dummy.mcfunction
function my_pack:folder/dummy2