Commands/testfor

From Minecraft Wiki
Jump to: navigation, search
Information icon.svg
This feature is exclusive to Bedrock Edition.
testfor
Restrictions

Operator

First introduced

Java Edition 1.5 (13w03a)
PE 1.0.5 (Pocket Edition alpha 1.0.5.0)

Removed

Java Edition 17w45a

Counts entities (players, mobs, items, etc.) matching specified conditions.

Syntax[edit]

testfor <victim: target>

Arguments[edit]

victim: target

Specifies the targets to count. Must be a player name or a target selector.
Permits entities other than players.

Result[edit]

Fails if the arguments are not specified correctly, or if victim: target fails to resolve to one or more entities (named players must be online).

On success, produces a success count equal to the number of targets matching victim: target, which can be measured by a redstone comparator facing away from the command block.

Examples[edit]

  • To test if Alice is online: testfor Alice
  • To count the number of players in survival mode within a 3-block radius of (0,64,0): testfor @a[x=0,y=64,z=0,r=3,m=0]
  • To count the number of zombies within a 20-block radius of (0,64,0): testfor @e[x=0,y=64,z=0,r=20,type=zombie]


History[edit]

Java Edition
1.513w03aAdded /testfor.
1.814w02aAdded dataTag argument to /testfor.
/testfor is no longer exclusive to command blocks.
14w07a/testfor can now test for partial NBT tag matches.
1.1317w45aRemoved /testfor.
Pocket Edition
1.0.5alpha 1.0.5.0Added /testfor.