Minecraft – How to use a command block to add coordinates to another command block

minecraft-commandsminecraft-java-edition

In the map I'm making, players will have to choose which items to switch. In this case, I will clone the first block over to the side, clone the second block to the first block's position, and clone the first block to the second block's position. I know this works, however, players will choose which blocks to switch. In this case, whichever buttons they press will set up the command blocks to work. This means that I will need to add coordinates to a given command without removing the command. Is this possible?

Best Answer

Yes, this is possible. You can update the blockdata of the command block. Try something like this command:

/blockdata [X, Y and Z of the command block you want to change the command of] {Command:"/COMMAND_WITH_NEW_COORDINATES"}