Doing operations with Minecraft command block is essential when making maps. Comparing numbers, multiplication, and division are common in game logic.
At the end of the page there’s a BONUS tip I use in many of my maps!
Operation Syntax
/scoreboard players operation <targets> <targetObjective> <operation> <source> <sourceObjective>
Beginners might be confused by this logic, so let me show what Minecraft does:
The order in which Minecraft performs the operation:
TAKES TARGET'S SCORE -> PUTS OPERATOR -> TAKES SOURCE'S SCORE
This will be our starting point: I created a dummy score called “apples” and assigned some values:
/scoreboard objectives add apples dummy
/scoreboard objectives setdisplay sidebar apples
/scoreboard players set Steve 5
/scoreboard players set Alex 3
Add two scores (Addition)
Here’s how you add two numbers in Minecraft, imagine Steve has 5 apples and Alex 2.
IN MATH:
5 + 2
SCOREBOARD:
/scoreboard players operation Steve apples += Alex apples
The result will be: Steve=7
Subtract two scores (Subtraction)
Here’s how to subtract two numbers in Minecraft, imagine Steve has 5 apples and Alex 2.
IN MATH:
5 - 2
(Steve - Alex)
SCOREBOARD:
/scoreboard players operation Steve apples -= Alex apples
The result will be: Steve=3
Minecraft calculates Steve minus Alex and then applies the result to Steve. (that’s why there’s an equal in the operator)
Multiply two scores (Multiplication)
Here’s how to subtract two numbers in Minecraft, imagine Steve has 5 apples and Alex 2.
IN MATH:
5 * 2
(Steve * Alex)
SCOREBOARD:
/scoreboard players operation Steve apples *= Alex apples
The result will be: Steve=10
Divide two scores (Division)
Here’s how to subtract two numbers in Minecraft, imagine Steve has 5 apples and Alex 2.
IN MATH:
5 / 2
(Steve / Alex)
SCOREBOARD:
/scoreboard players operation Steve apples /= Alex apples
The result will be: Steve=2 (Minecraft rounded up 2.5 to 2)
Summary: quick table
+= | Addition: Add second’s score to that of first |
-= | Subtraction: Subtract second’s score from that of first |
*= | Multiplication: Set first’s score to the product of first’s and second’s scores |
/= | Division: Divide target’s score by source’s score, and use the result (rounded down) to set the target score. |
= | Assign: Set target’s score to that of source |
%= | Modulus: Divide first’s score by second’s score, and use the remainder to set the first score |
< | Min: Set first’s score to second’s score only if second has the lesser score. |
> | Max: Set first’s score to second’s score only if second has the greater score. |
>< | Swaps first’s and second’s scores |
Do you like Minecraft Maps?
Hey, I'm Cimap! I love to amaze thousands of Minecraft players with my creations. Don't miss them out!