Skip to content

Equation (eq) Command

The eq command provides a simplified syntax for scoreboard operations, allowing you to write mathematical expressions in a more readable format than raw scoreboard commands.

eq <target> <objective> <operator> <expression>

Syntax Requirements

  • Scoreboard references must be in the format name objective with exactly one space between the name and objective
  • Integer literals only - decimal numbers are not supported
  • Parentheses can be used for grouping operations
  • Function calls and conditional expressions are not supported

Basic Assignment

Use = to assign a value to a scoreboard target.

Simple Assignment
Code
function example {
    eq player health = 20
}
example.mcfunction
scoreboard players set player health 20
Copy Assignment
Code
function example {
    eq target score = source score
}
example.mcfunction
scoreboard players operation target score = source score

Arithmetic Operations

The eq command supports standard arithmetic operators: +, -, *, /, %.

Addition and Subtraction

Addition Assignment
Code
function example {
    eq player score += 10
}
example.mcfunction
scoreboard players add player score 10
Subtraction Assignment
Code
function example {
    eq player health -= 5
}
example.mcfunction
scoreboard players remove player health 5
Subtracting from a Number
Code
function example {
    eq player health = 100 - player damage
}
example.mcfunction
scoreboard players operation player health = player damage
scoreboard players operation player health *= -1 mcb.eq.const
scoreboard players add player health 100

Multiplication, Division, and Modulo

Multiplication Assignment
Code
function example {
    eq target calc *= source value
}
example.mcfunction
scoreboard players operation target calc *= source value
Division Assignment
Code
function example {
    eq target result /= 2
}
example.mcfunction
scoreboard players operation target result /= 2 mcb.eq.const
Modulo Assignment
Code
function example {
    eq target remainder %= divisor value
}
example.mcfunction
scoreboard players operation target remainder %= divisor value

Complex Expressions

The eq command can handle complex mathematical expressions with parentheses and multiple operations. It follows standard mathematical order of operations (PEMDAS/BODMAS):

  1. Parentheses - Expressions in parentheses are evaluated first
  2. Multiplication, Division, Modulo - Evaluated left to right
  3. Addition, Subtraction - Evaluated left to right
Complex Expression
Code
function example {
    eq result total = base value + bonus score * 2 - penalty points
}
example.mcfunction
scoreboard players operation result total = base value
scoreboard players operation tmp0 mcb.eq.var = bonus score
scoreboard players operation tmp0 mcb.eq.var *= 2 mcb.eq.const
scoreboard players operation result total += tmp0 mcb.eq.var
scoreboard players operation result total -= penalty points
Parentheses and Order of Operations
Code
function example {
    eq target value = source a + (source b * 3 + source c) * 2
}
example.mcfunction
scoreboard players operation target value = source a
scoreboard players operation tmp0 mcb.eq.var = source b
scoreboard players operation tmp0 mcb.eq.var *= 3 mcb.eq.const
scoreboard players operation tmp0 mcb.eq.var += source c
scoreboard players operation tmp0 mcb.eq.var *= 2 mcb.eq.const
scoreboard players operation target value += tmp0 mcb.eq.var
Self-Referencing Operations
Code
function example {
    eq selfTarget main = selfTarget main + otherTarget alt * 2
}
example.mcfunction
scoreboard players operation tmp0 mcb.eq.var = selfTarget main
scoreboard players operation tmp1 mcb.eq.var = otherTarget alt
scoreboard players operation tmp1 mcb.eq.var *= 2 mcb.eq.const
scoreboard players operation tmp0 mcb.eq.var += tmp1 mcb.eq.var
scoreboard players operation selfTarget main = tmp0 mcb.eq.var

Negation

Use the minus sign to negate a value.

Negation
Code
function example {
    eq target result = -(source value)
}
example.mcfunction
scoreboard players operation target result = source value
scoreboard players operation target result *= -1 mcb.eq.const

Selectors

You can use @s as the name in a scoreboard reference, on either side of the operator. Other selectors, and @s with conditions such as @s[tag=example], are not allowed.

Using Selectors
Code
function example {
    eq @s score = @s base + 1
}
example.mcfunction
scoreboard players operation @s score = @s base
scoreboard players add @s score 1

Scoreboards

eq uses two scoreboards:

  • mcb.eq.var - Temporary values during complex calculations (tmp0, tmp1 and so on).
  • mcb.eq.const - The constant numbers that operations use, such as 2 in *= 2 mcb.eq.const.

MC-Build creates both scoreboards and sets the constants in a generated load function that it adds to the minecraft:load tag. You can change the scoreboard names with the eqVarScoreboardName and eqConstScoreboardName configuration options.

Optimizations

  • Constant folding: MC-Build adds, subtracts and multiplies number literals at compile time.
  • Add and remove: Adding or subtracting a number uses scoreboard players add or remove instead of operation.
  • Direct assignment: The first value is written straight to the target when possible, without a temporary value.
Optimization Example
Code
function example {
    eq player score += 5 + 3
}
example.mcfunction
scoreboard players add player score 8

Instead of creating temporary variables for 5 + 3, the compiler evaluates it as 8 at compile time.

Errors

These are compile errors:

  • A value that is not an integer or a name objective scoreboard reference, such as 3.14, abs(-5) or playerscore. The error is "Scoreboard entries must contain a space between name and objective".
  • A selector other than @s, or @s with conditions.
  • /= 0 and %= 0.

Warning

Division or modulo by zero inside a larger expression, such as eq player score = other score / 0, is not detected. It compiles to /= 0 mcb.eq.const.

Performance Considerations

Complex expressions with many operations will generate multiple temporary variables and commands. For performance-critical code, consider breaking down very complex expressions or using intermediate variables.