5

I found the /testfor command today in Minecraft, but when I use it in a command block it says

Usage: /testfor <player>

and when I do that it then says

/testfor must be used by command blocks with an analog output.

What does that mean and how can I use the command?

  • /testfor no longer exists in 1.13 – pppery Apr 14 at 1:24
3

As per the Minecraft Wiki Commands page, the syntax of the /testfor command is either of:

/testfor <playername>
/testfor <selector>

So, e.g., a command block that fires the command /testfor notch, with a redstone comparator attached to it, would output a signal from the comparator, assuming that Notch is playing on that server.

Using the Command Block selectors syntax lets you do things like /testfor @a[r=3], which will cause the comparator to emit a signal strength equal to the number of players within three meters. Or /testfor @a[m=2], which would cause the comparator to emit a signal strength equal to the number of Creative Mode players currently on the server.

2

The /testfor command has many uses. For example, you might want to testfor a player with a score of at least 3 on the red team. To do this, you would use the following command:

/testfor @p[score_objname_min=3,team=red]

In this command, you testfor the nearest player with a score, on the objective "objname", of 3. This player would have to be on the red team. If you attach this command block to a clock, and put a comparator on the side of it, whenever it finds a player, it will output a redstone signal.

Click HERE for a complete list of selectors that you can use within the square brackets.

2

You need to use it in a command block so that it can be in a clock or have a redstone input to trigger. You cannot use it from the chat.

You can use it in a lot of ways.

  • To get the closest player

  • To get the number of players in an area.

  • To apply an effect to an area

  • To apply certain commands when the testfor returns true.

  • Grab the nearest player with a certain scoreboard score.

To Check the result of the command, attach an comparator out of the command block. It will become powered if the /testfor finds a player matching the selector or name.

2

Suppose you did /testfor @p[r=3]. It would testfor a single player within 3 blocks.
Suppose you did /testfor @p[x=3,y=3,z=3]. It would testfor a player At Coordinates x=3, y=3 z=3.

protected by Community Mar 1 '14 at 18:13

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.