I am unfamiliar with command block scripts in Minecraft. However, I hear command blocks merely execute commands that users can do in the chat window (which I am mildly familiar with). Therefore, I must ask:

In the context of computer science terms, do variables and arrays exist in the command block programming language, or has anyone implemented them if they didn't exist originally?

The reason why I ask is because the existence of the ability to create arrays of variable size gives one the power to create an array implementation of the heap (dynamic memory allocator) along with many other useful data structures in a programming sense (trees, lists, sets, mathematical functions, etc.).

In fact, that would essentially give one the ability to implement many things in a pure data structure sense. With that context, one would merely need to implement the "physics" and "graphics" of an entity.

Having this feature of arrays and knowing the syntax for indexing arrays would give me great power in a matter of seconds to change the nature of scripting as I understand by simply writing libraries of functions for people to use.

  • 3
    Possible duplicate of Variables in Minecraft? – pppery Aug 20 '18 at 22:15
  • @ppperry no not even remotely. That's about parameters to scripts. This is about memory storage in general. I will not edit to say why my question is different because it is already clear just from reading them that they are not the same. – user64742 Aug 21 '18 at 0:12
  • The linked question says: "I would have a lot more possibilities if I could add variables to my commands. Is there anyway to do this? I have tried to use armor stands but it requires a command block for every single possibility." This is not what I am asking. They are specially asking about giving arguments to scripts. – user64742 Aug 23 '18 at 2:18

No, unfortunately there is nothing really quite like "variables" in Minecraft. However, there is the scoreboard, which you can use for certain things. If there's something specific you'd like to do, try asking that as well; you'll be surprised by the number of ways people have gotten around the absence of variables.

Here's a quick walk through of what you can do with the scoreboard:

/scoreboard objectives add name dummy - Adds objective name

/scoreboard players set|add|subtract entity objective value NBT Tag - Modifies objective score of entity, if entity's NBT data matches NBT Tag. NBT tag is optional.

/scoreboard players reset entity objective - Resets objective score if entity. Leave objective blank to reset all scores for this entity

Now for target selector arguments:

score_objective=value - Entities with a maximum objective score of value

score_objective_min=value - Entities with a minimum objective score of value

Hope this helped! Make sure to check out the Minecraft Wiki when in doubt. Here's a link to page on Scoreboards: Scoreboard - Official Minecraft Wiki

| improve this answer | |
  • What about arrays? I heard something about arrays that someone used. Was that something complicated they built? Also, is only addition and subtraction supported? – user64742 Oct 16 '16 at 18:27
  • 1
    A lot more than addition and subtraction is supported - check out the link in the answer ('scoreboard players operation' command). – Kcats Oct 16 '16 at 19:26
  • No, as far as I know, there is no replacement for arrays in Minecraft. And thanks Kcats, I didn't realise there was so much more functionality with scoreboards! – atoms118 Oct 16 '16 at 20:10

Minecraft commands do have a form of variables, but, unfortunately, they can only store numeric values. This is called the scoreboard, and you can add and access variables by using the /scoreboard command. A list of all the functions you can preform is available here.

| improve this answer | |

In the german Minecraft technic wiki you find "Arrays" with one dimension in this article, it is german, but the commands are listed:


| improve this answer | |
  • Awesome. One dimensional arrays allow for a lot of stuff (ironically including multidimensional arrays). Do you know if any arithmetic operations can be performed on the elements of these arrays? – user64742 Jul 12 '17 at 20:33

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.