mojira.dev
MC-129038

Some selectors work in chat but not in cmd blocks/functions

Executing the following command in chat succeeds (when a player is between y=0..58), but running it in a command block/function does not work.

"execute as @a[y=0,dy=58] run say found player"

Comments 1

The command still works, but the location the command is run from is different. Since you didn't specify x and z coordinates but y coordinates, the player that is matched needs to be in the same x/z coordinates as the command block. (Edit: I agree that's a little unintuitive, but it's been like that since command blocks exist)

You can test that with the commands

/execute positioned ~ ~ ~ run say @a[y=0,dy=100]

(works) and

/execute positioned ~1 ~ ~ run say @a[y=0,dy=100]

(doesn't work).

It was the same in 1.12.2, try

/execute @s ~ ~ ~ say @a[y=0,dy=100]

(works) and

/execute @s ~1 ~ ~ say @a[y=0,dy=100]

(throws an error).

Also, if you put your command into a command block, the command will succeed if you're directly above or below the command block.

To fix your problem, use

/execute as @a at @s if entity @s[y=0,dy=58] run say found player

NOPEname

(Unassigned)

Unconfirmed

Minecraft 18w16a

Retrieved