Minecraft – How to use Gamerule variables in commands

minecraft-commandsminecraft-java-edition

I'm attempting to get my head around the minecraft "Gamerule global variables" (e.g. custom game rules which you can use to store a value) but there seems to be very little useful info about them available.

For instance: /gamerule TestVar 10 creates a new variable.

I would like to be able to use this in another command, such as a fill command, e.g. something along the lines of:

/fill ~ ~1 ~ ~ ~[TestVar] ~ minecraft:stone 0 keep 

(This command would create a stone tower on top of the command block with a height equal to the TestVar. In the case above, it would be 10 high)

Is there any way to use a variable like this inside a command?

Update: I am open to using scoreboards, objectives, stats or anything else in vanilla minecraft. I'd just like to be able to insert a variable value into a static command.

Best Answer

You can't

In the current state of the game, Minecraft 1.8.8 or Snapshot 15w42a, there is no way to insert any sort of variable into commands.

There are definitely workarounds to this for many possible applications of variables in commands, mostly involving the use of execute and armor stands, but there is no general way of using variables in commands. These workarounds are never simple, too, and brute-forcing the commands might actually be more efficient.