Generate a command block with variable data

Generate a command block with variable data - Crop hacker silhouette typing on computer keyboard while hacking system

I'm trying to setblock a command block with variable data in it. I want to make a variable sized array with an armor stand, and read a custom tag at a variable position. This position should be stored in a scoreboard as well.

Further information:

  • Minecraft version 1.13.2
  • Singleplayer mode

I've already tried this command:

/setblock ~ ~2 ~ minecraft:command_block{Command:{"text":"execute store result score posN replay run data get entity highfrequent Pos["},{"score":{"name":"#this","objective":"replay"}},{"text":"]"}} replace

But it doesn't work. It couldn't place the block, and I think I did something wrong with the JSON syntax.

My objective is to have an array which I can read at a variable position.

If anybody has an idea of how to do this, I would be glad to hear it.



Best Answer

The command inside a command block is a regular string, not a JSON component. Since there's also no way to convert a JSON component into a normal string, you can't use it as the command inside a command block.




Pictures about "Generate a command block with variable data"

Generate a command block with variable data - From above of crop anonymous male hacker typing on netbook with data on screen while sitting at desk
Generate a command block with variable data - Black Screen With Code
Generate a command block with variable data - Javascript Code



Can you use variables in command blocks?

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.

How do you get data from a command block?

It can either be obtained by using the pick block control, or by using various commands, such as /give @s minecraft:command_block , or /setblock ~ ~ ~ command_block . Just like other blocks that can store NBT data, using pick block + CTRL copies the command and options inside the command block.

How do I change my block data in Minecraft?

You change the data tag for a block using the /blockdata command in Minecraft. TIP: Starting in Minecraft Java Edition (PC/Mac) 1.13, the /blockdata command was replaced by the /data command.

How do you use the entity data command in Minecraft?

You can use the /data command to get, merge and remove NBT tags (formerly called data tags) for entities and block entities. The /data command is most useful for changing attributes of a mob after the mob has spawned or modifying attributes of a block entity after you have placed it.



Minecraft Data Command [1.19] Tutorial




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Anete Lusina, Sora Shimazaki, Antonio Batinić, Markus Spiske