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.

  • What version of Minecraft is this? – Fezodge Oct 18 '15 at 19:28
  • 2
    @FezodgeIII The latest full release (1.8.8) – DBS Oct 18 '15 at 19:33
  • 1
    The only think you can really do is get the gamerule into a scoreboard score, then do whatever you could do with that normally. You cannot insert it directly into a command. – SirBenet Oct 18 '15 at 20:26
  • @colorfusion Yeah, I was getting to that conclusion myself, but it just seems like such a useful thing to be able to do that I thought there might be some way to work around it. – DBS Oct 18 '15 at 20:32
  • Custom gamerules no longer exist in 1.13 – pppery Jul 8 '19 at 20:51

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.