MCCompiled Wiki 1.19 Help

Built-In Functions

MCCompiled ships with a list of built-in functions which are already implemented for your use. Functions can either support compile-time, runtime, or both.

When a function supports runtime, it follows the same rules as functions, as in, it is only included in your project's output when it's used somewhere in your code.

Utility Functions

These functions are miscellaneous useful utilities that can help with writing MCCompiled code. Metaprogramming, math, and other various functions allow you to write better code.

Get Value by Name

getValue(name) compile-time


Fetches a value by the given name and returns it to be used as if its identifier was specified. An example of this in action looks like the following:

define int exampleValue ‎ getValue("exampleValue") = 40
Fetch E0 Glyph

glyphE0(x, y = 0) compile-time


Fetches the character at a coordinate in glyph_E0.png and returns it as a string literal. The coordinate 0, 0 is the top left.

Fetch E1 Glyph

glyphE1(x, y = 0) compile-time


Fetches the character at a coordinate in glyph_E1.png and returns it as a string literal. The coordinate 0, 0 is the top left.

Minimum

min(a, b) compile-time, runtime


Returns the smaller of the two inputs.

Maximum

max(a, b) compile-time, runtime


Returns the larger of the two inputs.

Count Entities

countEntities(selector) runtime


Returns the number of entities which match the input selector as an integer.

define int players ‎ players = countEntities(@a)

Math Functions

These functions work with numbers and computation beyond what the operators can do.

Random

random(range) compile-time, runtime


Returns a random number. Supports input of either a single value or a range. When a range is specified, the minimum and maximum values will be used (inclusive). When a single value is specified, the range (0..n-1) is used.

define int choice ‎ // both cases can be 0, 1, 2, or 3 choice = random(0..3) choice = random(4)
Square Root

sqrt(n) compile-time


Returns the square root of n. Runtime support is planned eventually.

Sine

sin(n) compile-time


Returns the sine of n. Runtime support is planned eventually.

Cosine

cos(n) compile-time


Returns the co-sine of n. Runtime support is planned eventually.

Tangent

tan(n) compile-time


Returns the tangent of n. Runtime support is planned eventually.

Arc-tangent

arctan(n) compile-time


Returns the angle that has a tangent of n. Runtime support is planned eventually.

Rounding Functions

These functions focus on decimal numbers; specifically, rounding them to integers in different ways.

Round

round(n) compile-time, runtime


Rounds the given number to the nearest integer. If the number is a midpoint (e.g., 1.5), the number is rounded up.

Floor

floor(n) compile-time, runtime


Rounds the given number to the nearest integer that is less or equal to it. Generally referred to as "rounding down."

Ceiling

ceiling(n) compile-time, runtime


Rounds the given number to the nearest integer that is greater or equal to it. Generally referred to as "rounding up."

Last modified: 28 October 2024