How do I invert the /testfor command's result?

Solution 1:

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.

Solution 2:

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]