Attributes
Attributes are modifiers that change the way values or functions work. They can be specified in most places in definition commands (define
or function
).
Value Attributes
The following contains all attributes that can be applied to values, as well as examples and use-cases where applicable.
- global
Makes the attached value global, meaning that the value's scoreboard objectives are always tied to the global fakeplayer
_
.Any attempts to use clarifiers on the value will result in a compile-time error. The value is guaranteed to never be attached to an entity.
Examples & Use-case
Making values global is useful for anything that applies to the world, and not a specific player/entity. If you were designing a mini-game, for example, you would want the game-related code to be global, along with the compile-time guarantees that it will remain global.
define global int playersPassed define global time timeRemaining function display { globalprint "PASSED: {playersPassed} | TIME LEFT: {timeRemaining}" }- bind
Binds the value to a given MoLang query. Requires one parameter, being a string that contains the query to use. The current list of supported bindings is here.
Most bindings come with pre-defined entities they attach to, but in cases where they don't, the entities can be manually specified by adding more string parameters to the end of the function, i.e.,
bind("query.is_sleeping", "fox")
to bind specifically to foxes.Examples & Use-case
Binding replaces all cases where animation controllers were needed to access extra information about entities.
define bool bind("query.is_sleeping") isSleeping if not isSleeping { summon lightning_bolt print @a "{@s} IS RUINING THE SMP!!!" }
Function Attributes
The following contains all attributes that can be applied to functions, as well as examples and use-cases where applicable.
- extern
Makes a function external. External functions cannot have code in them, and their parameter names are interpreted verbatim. These functions will call the
.mcfunction
that matches their name and folder, making them great for combining MCCompiled with optimized handwritten functions or code from non-MCCompiled users.Examples & Use-case
In cases where you have an
.mcfunction
file that cannot be ported or is not necessary to port over, it's better to declare an external function; making it possible to call the.mcfunction
directly.// BP/functions/library/example.mcfunction function extern library.example library.example()- export
Marks a function for export. The function and any functions it calls will always be exported whether they're in use or not. See more about usage/exports here.
Examples & Use-case
Excluding unused files is beneficial for many projects, but sometimes you'll have functions you run in-game through a command block, the
/function
command, or other methods MCCompiled doesn't know about. The export attribute covers those edge cases. In this example, the user wants to run/function reset
in game.function export reset { kill @e[type=item] itemsCollected[*] = 0 print "Reset everything!" }- auto
Makes the function automatically run every tick; or, if specified, at an interval. If the attribute is specified as-is, the function will be marked as "in use" and added to
tick.json
. If a parameter is given in ticks, the function will run on that interval using an auto-generated timer.Examples & Use-case
Anywhere
tick.json
is needed, or something needs to happen on a timer, the auto attribute saves lots of boilerplate code and clearly communicates which functions automatically run. In the example below, time suffixes are used instead of tick count.function auto everyTick { // logic to run every tick. } function auto(1s) everySecond { // logic to run once a second. }- partial
Makes a function partially implemented. When a function is partial, you can re-define it later as many times as you want, with each one appending its contents to the original function.
Examples & Use-case
Partial functions are useful with metaprogramming or forward declaration, where you may want to use a function before its actual implementation. The following example shows how a function can be defined in two different places with their results merged.
function partial example { print "One!" } function partial example { print "Two!" } example() // One! // Two!