MCCompiled Wiki 1.19 Help

Comparison (compile-time)

Comparison is the backbone of logic in both runtime and compile-time code. This page will focus on the compile-time side of comparison.

Simple Comparison

Comparison is formatted universally the same. The primary way of performing a comparison is using $if, but the $assert command also shares the same syntax. Comparison compares the left and right side using one of six different operators:

Checks if the left and right sides are equal to each other.


$if left == right { // ... }

Checks if the left and right sides are not equal to each other.


$if left != right { // ... }

Checks if the left side is less than the right side.


$if left < right { // ... }

Checks if the left side is less or equal to the right side.


$if left <= right { // ... }

Checks if the left side is more (greater) than the right side.


$if left > right { // ... }

Checks if the left side is more (greater) or equal to the right side.


$if left >= right { // ... }

Using If

The $if command runs a comparison and performs the next statement/block only if it evaluates true.

The example below shows a macro which runs effect @s clear if the input effect is equal to "clear."

$macro giveEffect effectName { $if effectName == "clear" effect @s clear }

Using Else

The $else command looks at the result of the last $if command that was run in the same block, and only performs the next statement/block if that $if command didn't result with true. It's essentially the inverse.

This example expands and finishes the above example by adding $else to cover cases where the effect is not "clear."

$macro giveEffect effectName { $if effectName == "clear" effect @s clear $else { // give them the effect effect @s $effectName ‎ // let them know what effect they've received $strfriendly effectName print "You've received the effect $effectName!" } }
Last modified: 28 October 2024