MCCompiled Wiki 1.19 Help

Types

Values can have their own types, a way of changing how they interact, add, display to users, convert, etc... You can think of types as presets that change everything about the value in a way that is unified and makes sense.

The greatest thing about types in MCCompiled is that they are very back-seat. They work as you would expect and don't require you to think about conversion anywhere. If it makes sense, then everything just works.

Defining Value with a Type

When defining a value, you optionally can specify a type when using define [type] [name]. The most common type is the int

Built-In Types

The int is identical to a Minecraft scoreboard objective.

Limits

Integers are limited to -2^31 to 2^31 - 1. If you overflow an integer by making it exceed these limits, it will wrap back around into the negatives/positives depending on which way you overflowed.

Display

When displayed to a player, integers are shown as-is with no formatting applied.

Language Features

Integers support all default language features.

Example

define int exampleValue exampleValue = 42 exampleValue += 10 print "The value is: {exampleValue}" // The value is: 52

The decimal can be a decimal number. They're represented as a single scoreboard objective as a fixed point number. As such, decimal numbers need to have their precision specified at the time of definition: decimal [precision]

Limits

Decimals are limited based on their precision. -2^31 * (0.1^precision) to 2^31 - 1 * (0.1^precision) if you overflow an integer by making it exceed these limits, it will wrap back around into the negatives/positives depending on which way you overflowed.

To prevent from overflowing prematurely, use precisions as low as you're comfortable with and avoid multiplication or division with numbers that are of precision 3 or higher (as a general rule; not applicable everywhere).

Display

When displayed to a player, decimal numbers are displayed as expected, using a . to denote the decimal part. Zeros will pad the left side of the decimal part, if needed.

Language Features

Decimals support all default language features. When an operation is performed between two decimal numbers and their precisions don't match, the right-hand value is always scaled to match the precision of the land-hand value automatically.

Additionally, if you define a value without a type, opting to specify a decimal number instead, the precision of the defined value will accurately reflect the input. 3.14 would be given a precision of two, 1.5 would be given a precision of one, etc...

Example

define decimal 3 exampleValue exampleValue = 42.521 exampleValue += 10.1 print "The value is: {exampleValue}" // The value is: 52.621

The boolean can be either true or false. They're represented as a single scoreboard objective that is either one (true) or zero (false).

Limits

Booleans are limited to only two values by design, as they represent a limited state. They can be set to the literal true or false, nothing else.

Display

When displayed to a player, booleans are represented as pieces of text; by default, this is "true" or "false." This can be changed by setting the preprocessor variables _true and _false respectively to the string you wish to be displayed. When localization is enabled, entries are automatically created as with any other strings.

Language Features

Booleans do not support arithmetic, only assignment, comparison, and display. The if command supports placing only the boolean variable on its own without needing any comparison operators. When this is the case, the boolean value will be checked to see if it's true.

Example

define boolean isGameRunning isGameRunning = true ‎ // Setting how the boolean will be printed to players $var _true "Running" $var _false "Paused" ‎ print "Game Status: {isGameRunning}" // Game Status: Running

The time acts the same as a regular integer, but with extra features for display.

Limits

Time values have the same limits as integers; limited to -2^31 to 2^31 - 1. If you overflow a time by making it exceed these limits, it will wrap back around into the negatives/positives depending on which way you overflowed.

Display

When displayed to a player, times are formatted based on the _timeformat preprocessor variable. This variable is a string using lettering and colons to describe how the time should be divided, and where zeros should be inserted.

Time Format

The default time format is m:ss. This implies that the number of minutes should be displayed (m), and the number of seconds should be displayed after it (s). The two s's indicate that they should be padded to always have a width of 2, so if the number of seconds is, for example, 6, then it should display as 06.

Let's try with h🇲🇲ss. It will display the number of hours padded to a width of 1, the number of minutes padded to a width of 2, and the number of seconds padded to a width of 2; example: "0:12:05"

Language Features

Times support all default language features, including time suffixes.

Example

define time timeRemaining timeRemaining = 1m + 30s timeRemaining -= 7s ‎ // Setting how the time will be printed to players $var _timeformat "mm:ss" ‎ print "Time Remaining: {timeRemaining}" // Time Remaining: 01:23
Last modified: 28 October 2024