Minecraft Java Edition Commands – How to Swap Two Scoreboard Values

minecraft-commandsminecraft-java-edition

I am making a redstone computer, and I am done making increment value, decrement value, goto function with index, stop signal, and other small things, and all is working. I am storing the main calculation value in a scoreboard value named Reg1. I would like to add a Reg0/Reg2, and I would like to know if there is any possible way to do something like: /scoreboard players set @p Reg1 Reg2, or anything like that? I want to set one variable equal to another.

I do not want to have a large amount of blocks having /testfor @p[score_Reg1 = 1] and then /scoreboard players set @p Reg2 1 and then doing the same with 2, then 3, etc…

Best Answer

This can be accomplished using /scoreboard players operation:

/scoreboard players operation <target1> <objective1> <operation> <target2> <objective2>

The available operations are:

  • += Addition: increase first first score by second
  • -= Subtraction: decrease first first score by second
  • *= Multiplication: multiply the first score by the second
  • /= Integer Division: divide first score by second
  • %= Modular Division: set first score to the remainder when it's divided by the second
  • = Assign: set first score to the second
  • < Min: set first score to the min of either score
  • > Max: set first score to the max of either score
  • >< Swap: swaps the scores around

What you want to do should be:

/scoreboard players operation @p Reg1 = @p Reg2