2

Following up on an almost identical question you can find here, I would now like a solution that works in Minecraft Bedrock Edition.

Here is the text of the other question:

/testfor, /testforblock, and /testforblocks are all part of the same group of commands and are similar in what they do after their test. They are only useful when their output is measured using redstone comparators (not recommended) or when combined in a chain with other commands (most often way)
It's quite simple. If the test returns TRUE, any conditional command blocks later in the chain will run (unless stopped by a different failed command in between). If the test returns FALSE, the conditional command blocks won't run.
I would like to invert the check, so that if the entity does not exist /testfor, or if the block is not what is specified /testforblock, or if the block regions don't match/testforblocks, then the subsequent commands in the chain will run, and if the check passes, they will not run. How can I do this?
(I suspect that for /testforblock, it's as simple as placing a ! before the block name, but I'm not sure if the ! operator existed in 1.12. For /testfor and /testforblocks, absolutely no idea.)

You can find the accepted answer by clicking on the link above. However, this solution does not work in Bedrock Edition, as I cannot test for NBT tags like {SuccessCount:1}.

How can I accomplish this task? The only thing I can think of is using comparators and a redstone torch, but I'm 99% sure there is a better way.

8
  • I shouldn't have to say this, but for the love of god, don't use testfor! It was all but deprecated in the Java Edition since 1.8 or 1.9, and the same is currently true in Bedrock Edition. testfor was only ever the right tool when wielded by super star command technicians, and if you have to ask a question like this, that's not you. Learn the scoreboard and execute instead; they'll let you do so much more than testfor ever can.
    – MBraedley
    Commented Jul 11, 2020 at 20:58
  • I mean what I said, and only left out the fact that it was removed in 1.13 of the Java Edition. That's what happens to things that are deprecated: they get removed.
    – MBraedley
    Commented Jul 11, 2020 at 21:12
  • @MBraedley So you’re saying that the /testfor command can be replaced with scoreboards and the /execute command. I don’t see how this is possible. I’ve been using /testfor for quite a while now, and I don’t see how /execute would be a good replacement.
    – One 2 Many
    Commented Jul 13, 2020 at 2:57
  • Yes, everything that can be done with testfor can be done with a combination of execute and scoreboards, plus a few more things. Trying to bend testfor to your will instead of learning the power of the scoreboard and execute is the surest sign that someone is a novice at commands.
    – MBraedley
    Commented Jul 13, 2020 at 3:20
  • @MBraedley Huh, interesting to know. Can the same fact be applied to /testforblock and /testforblocks?
    – One 2 Many
    Commented Jul 13, 2020 at 3:43

2 Answers 2

2

It's possible. You want a command to execute on a failed detection, so you'll have to chain that command to a different block that scans the block doing the detecting, and compares it to an identical one that is intended to always fail to detect.. I'll try to explain..

Say you have a command block that is trying to detect something at ~ ~1 ~ but it finds no target.. say there is another identical to it, but it IS finding a target at ~ ~1 ~. Say there is a third command block that is comparing the first two to detect if they are identical. They will not be identical until they are either both successful, or both unsuccessful at detecting the target at the time of check. You want them both to match as unsuccessfully detecting a condition, which will successfully be detected and chained from when the third block scans and continues its own chain. If both of the first two were to fail to detect a target, they would match according to the third command block which would allow a chain command block to execute a new command from that third block detecting unsuccessful command execution.

1

In bedrock you have to use testfor because execute hasn't been updated to include conditional logic yet (the only conditional logic available to execute on bedrock is to check for a specific block type relative to the entity)

If you place a comparator facing away from a command block running testfor it will output a redstone signal power level equal to the number of entities found. If you run this signal into a block with a redstone torch it effectively gives you a redstone signal inverting the testfor condition. Just run that signal into other command logic.

Another possibility is to use the '!' operator in your test selector:

/testfor @e[type=!player]
2
  • Huh, so maybe I was right that redstone is the only way. I had mentioned this in the original question, and I was 99% sure that there is a redstone-free way to accomplish this task. If you can find one, let me know by adding another answer.
    – One 2 Many
    Commented Jul 20, 2020 at 18:41
  • 1
    And also, your suggestion of using the ! operator doesn't work. The provided command tests if there are any non-player entities, not if there are no players.
    – One 2 Many
    Commented Jul 20, 2020 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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