Forum: gaming.stackexchange.com
Tags: <minecraft-java-edition><minecraft-commands>
Title: Order of command block execution if triggered at the same time?
Question: If I make some  Command Blocks  with commands (let's say  say whatever ), connect them with redstone dust ( you can place redstone dust on Command Blocks by holding   Shift ), then produce a redstone signal to trigger them at the same time, is there a specific order in which they are executed? Does it depend on coordinates, directions, or what?

Answers:
sents: text: In Minecraft 1.9 command blocks get an overhaul.
text: There will be three modes of command blocks: Impulse :
text: Regular behavior, command gets activated via redstone Repeat : The command in this command block gets activated every tick (superfast clock) Chain : This is the one you're looking for, see below
text: Command blocks also have a direction now, they can face north, south, east, west, up or down, this is important for the chain command blocks.
text: When any command block gets activated, it will activate the chain command block that it is pointing into.
text: This means you can build chains out of command blocks, whose commands get activated in the order they are pointing into each other.
answer_details: author: gaming.stackexchange.com/users/30132/Lars
score: 9
sents: text: This is not a good idea.
text: If you have commands that must be executed in a specific order, separate them with repeaters or comparators so that they execute in a specific order.
text: If you trigger a lot of command blocks with interfering actions at the same time, they will execute in a specific order, but you can't know what this is in advance, it may change without notice (if the server is restarted for instance), and will almost certainly cause you a lot of headaches.
answer_details: author: gaming.stackexchange.com/users/3610/fredley
score: 6
sents: text: It starts with the lowest z coordinate, then runs them in order of increasing x coordinate, then starts again with the next z coordinate.
text: I do not know how the y coordinate is involved.
answer_details: author: gaming.stackexchange.com/users/70248/Bloons113744
score: 6
sents: text: You really don't want to be using redstone dust in your command block contraptions, or in this case, even repeaters.
text: I discuss this further in this answer .
text: There are much better solutions these days, and even better solutions to come in the near future.
text: So for 1.8, what you want to be using is a 20Hz fill clock .
text: There are 2 great features about fill clocks, plus some other advantages.
text: The first feature is that every command runs every game tick, i.e. 20 times a second.
text: The second feature is that execution is well defined, at least when everything is in the same chunk.
text: If your command blocks are in a single line along the X or Z axis, the command blocks will be executed from low coordinate to high coordinate.
text: One of the other advantages is that fill clocks generally produce less lag than redstone.
text: But fill clocks are old hat now.
text: The new hotness is command block chaining, which is coming in 1.9, and is available now in snapshots.
text: These are even better than fill clocks because while both run at 20Hz, the new command blocks produce even less lag and command execution is even easier to determine.
text: If you're working with command blocks, you should be using 1.9, even though, at the time of writing, it hasn't been fully released.
answer_details: author: gaming.stackexchange.com/users/1351/MBraedley
score: 4
sents: text: In fact, it is actually the lowest z, then executes that row of x, then goes +z by 1, then executes that row of x
text: and so on...
text: for y-execution, it goes bottom-up, so it starts at the lowest point, then goes to the lowest z point, the executes that row of x.
text: It's actually not that hard, and really compact instead of a line of repeaters running from each command block.
answer_details: author: gaming.stackexchange.com/users/80534/SkyBlue_
score: 2
sents: text: If the command blocks trigger each other by placing and removing redstone blocks, wires, circuit-breaking opaque blocks and/or inputless torches, then they're predictable (at least as long as the chunks never unload -- see https://bugs.mojang.com/browse/MC-711 ).
text: They'll be triggered from bottom to top, then from west to east, then north to south (ascending order of Y, then X, then Z), and a command block will run each game tick if its signal has switched from off to on at least once since it last ran.
text: (The same rule applies to note blocks, which are the only type of output block that can run at more than 5 Hz.)
text: This is what makes 20Hz /setblock
text: clocks possible.
text: It's only when you use repeaters, comparators, switching torches, or moving parts that the unpredictability arises.
answer_details: author: gaming.stackexchange.com/users/93873/Pr0methean
score: 1
sents: text: TL;DR :
text: The answer varies from where you activate the command blocks.
text: I did an experiment with these where all command blocks are programmed with /say
text: Whatever at
text: and then their coordinates.
text: Next I activated them from all sides.
text: The lever at 165 -245:
text: The lever at 169 -240:
text: The lever at 173 -245:
text: The lever at 169 -250:
text: Then, I made sure the test was consistent.
text: As you can see, the first time it activated in this order: 166 -245 168 -245 167 -245 169
text: -245 169 -244 169
text: -246 170 -245 169 -243 169 -242 169 -241 169 -247 169
text: -248 169 -249 172 -245 171 -245
text: The second time it activated in this order: 166 -245 168 -245 167 -245 169
text: -245 169
text: -244 169 -246 170 -245 169 -243 169
text: -242 169
text: -241 169 -247 169
text: -248 169 -249 172 -245 171 -245
text: Those two are exactly the same.
text: In conclusion, the order depends on where the signal was activated.
answer_details: author: gaming.stackexchange.com/users/118326/Rainbow Dash
score: 1

Summary of the answers:
You can build chains out of command blocks and you can get them to execute in a specific order. The order depends on where the signal was activated.
Command blocks do get triggered in a specific order. That order can be tracked via different methods, such as knowing the numeric value of coordinates.