Minecraft – In command block scripting, do arrays (or even variables for that matter) exist

minecraft-commandsminecraft-java-edition

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.

Best Answer

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