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 objectivewith 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
function example {
eq player health = 20
}
scoreboard players set player health 20
Copy Assignment
function example {
eq target score = source score
}
scoreboard players operation target score = source score
Arithmetic Operations
The eq command supports standard arithmetic operators: +, -, *, /, %.
Addition and Subtraction
Addition Assignment
function example {
eq player score += 10
}
scoreboard players add player score 10
Subtraction Assignment
function example {
eq player health -= 5
}
scoreboard players remove player health 5
Subtracting from a Number
function example {
eq player health = 100 - player damage
}
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
function example {
eq target calc *= source value
}
scoreboard players operation target calc *= source value
Division Assignment
function example {
eq target result /= 2
}
scoreboard players operation target result /= 2 mcb.eq.const
Modulo Assignment
function example {
eq target remainder %= divisor value
}
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):
- Parentheses - Expressions in parentheses are evaluated first
- Multiplication, Division, Modulo - Evaluated left to right
- Addition, Subtraction - Evaluated left to right
Complex Expression
function example {
eq result total = base value + bonus score * 2 - penalty points
}
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
function example {
eq target value = source a + (source b * 3 + source c) * 2
}
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
function example {
eq selfTarget main = selfTarget main + otherTarget alt * 2
}
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
function example {
eq target result = -(source value)
}
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
function example {
eq @s score = @s base + 1
}
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,tmp1and so on).mcb.eq.const- The constant numbers that operations use, such as2in*= 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 addorremoveinstead ofoperation. - Direct assignment: The first value is written straight to the target when possible, without a temporary value.
Optimization Example
function example {
eq player score += 5 + 3
}
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 objectivescoreboard reference, such as3.14,abs(-5)orplayerscore. The error is "Scoreboard entries must contain a space between name and objective". - A selector other than
@s, or@swith conditions. /= 0and%= 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.