# How do I find the absolute value of a score?

So I want to find the absolute value of two coordinates in Minecraft 1.16.3 to see how far apart they are. So I make the cords into scoreboard values so I could use operations. Could I use the pipes or '|' like in math. How would I do it without a bunch of other commands to test if the values are below 0 or something. If any data packs are needed that's fine. I just wanted to know if I could do it like in normal math e.g. |1-10| that equals 9. Thanks for helping!

• While I know absolutely nothing about scoreboards in Minecraft, if you square a number and then take the square root of the result, it will give you the absolute value Oct 27, 2020 at 23:52
• Actually, I think this question will give you the information you're looking for Oct 28, 2020 at 0:00
• I'm not sure entirely the exact commands on doing this, couldn't you check if its less than `0` and if it is then multiply it by `-1` and if not just leave it alone? Oct 28, 2020 at 3:00

I found what I think is a very simple way. The only math operations available with the scoreboard are `+=`, `-=`, `*=`, `/=`, and `%=` (modulo, like in coding).
The setup is complex, but the math used is simple and elegant. Bear with me.

Here are the scoreboard objectives I'll be using:

• `const`: A constant values scoreboard.
• `vals`: A scoreboard objective where you input all the values. With the press of a button, all the values in this scoreboard are replaced with their respective absolute values.
Important notice: If there are other scoreboard machines in your world, you can't use fake players for this. You'll need to use armour stands to store your scoreboard values.
Sorry, that's what makes this setup complex. If I find a better way, it'll be up here before you can say Jack Robinson.

First, run this command:

``````/scoreboard players set -1 const -1
``````

The command in the command block is:

``````/execute as @e[scores={vals=..2147483647}] if score @s vals matches ..-1 run scoreboard players operation @s vals *= -1 const
``````

If any of the scores on `vals` is −1 or below, multiply them by −1.

• Thanks, it worked! Did you mean to type temp instead of test in the 3rd line of code in the score selector? Oct 28, 2020 at 15:00
• @randomuser922 No, I just mixed up the objective names with the actual ones on my world. (I used `test` and `abs` instead of `vals` and `temp`) Oct 28, 2020 at 17:38