The new /execute
command gives detailed control over the command context given to a command that is to be executed. However, the way command contexts are computed doesn't account for the fact that command context may change in iterations of the outer loop and should then be different in subsequent iterations.
For many use-cases this is perfectly fine because the command context rarely (intentionally) changes. However, for some applications this is not sufficient. Consider the following command, ran when exactly one player and a couple of other entities are in the game:
/execute as @e at @p run tp @p ~ ~ ~1
Expected behavior: the player is teleported one block for each entity in the world. If there are 10 armor stands and the player, the player should be teleported 11 blocks. Actual behavior: the player is teleported one block. A reproduction case not involving teleportation can be found in this comment.
The following is a simplified, pseudo code interpretation of how /execute
looping is understood to work with this command:
compute contexts for all loops
loop over @e
loop over @p
stitch together computed command context
run "tp @p ~ ~ ~1" with computed command context
Instead, it should work somewhat like this:
calculate contexts for @e loop
loop over @e
calculate contexts for @p loop
loop over @p
stitch together context for this iteration
run tp @p ~ ~ ~1 with computed command context
Note that the implementation of /execute
wasn't looked at in detail for this ticket, so it contains a healthy dose of speculation.
Linked issues
is duplicated by 1
Comments 12
@violine1101
I'm sorry. There was wasted space in the command.
execute @e[c=2] ~ ~ ~ tp @p ~1 ~ ~ ~90 ~
This command is valid in 1.12.
With this command, you will move two blocks and rotate 180 °.
No, that command will move you one block and rotate you 90° as well. Maybe the command was simply run twice?
@violine1101
Perhaps you are doing it in a world where there is no one other than yourself?
My writing is based on the assumption that there are two or more entities.
Oh. I misunderstood your commands. Stupid me.
Now, this is what the command does in 18w06a: It teleports you one block and rotates you 180°. Apart from myself, there's only an armor stand in the world. I'm not exactly sure why I got a different result than you.
@violine1101
I hope that a way to rotate and move twice even if the bug is fixed be added.
In the current specification, I have to create a function each time.
@@unknown: Updated summary and description. Let us know if we missed any important information from the old description.
Here is a repro without teleport:
/scoreboard objectives add TEMP dummy
/scoreboard objectives setdisplay sidebar TEMP
/scoreboard players set @p TEMP 1
/execute at @e[limit=2] as @p at @s[scores={TEMP=1}] run scoreboard players add @s TEMP 1
EXPECTED: final score of 2
ACTUAL: final score of 3
This demonstrates that the second 'at' is evaluating @s only once at the start, rather than in each iteration of the outer limit=2 loop.
This is not a valid command, neither in 1.12, nor in 1.13.
That's what the command is supposed to do, what did you expect?