Minecraft – How to use a dumthe’s scoreboard value inside a command

minecraft-commandsminecraft-java-edition

What I mean by the title is, for example, say I have a dummy type scoreboard with the value of 4 for me. How would I, say, effect myself speed level 'the value in the scoreboard', or give myself an enchanted sword with the sharpness level of the scoreboard's value… stuff like that.

Note: I am using 1.8

Best Answer

1.12−

The thing is, although there should be a simple answer for this, there isn't. I haven't been able to find a way to do this, except for doing one check per level, for example, running the following...

/give @p[score_dummy=4,score_dummy_min=4] diamond_sword 1 0 {ench:[{id:16,lvl:1}]}

...rinse and repeat for each level!

This can get very repetitive, especially in older versions, which aren't that good at converting between NBT and scoreboard values.

1.13+

I have a simple solution using clever modification of the /execute command!

Run the following two commands in order:

/give @p diamond_sword{Enchantments:[{id:"minecraft:sharpness",lvl:1s}]}
/execute store result entity @p Inventory[{id:"minecraft:diamond_sword"}].tag.Enchantments[{id:"minecraft:sharpness"}].lvl short 1.0 run scoreboard players get @p dummy

This command will give the player a diamond sword, and then modify it to the correct level of Sharpness.