1.13 Detect if no mobs with a specific tag exist and execute commands

My 1.12 solution can be found here. When trying to update command blocks to 1.13, I have the following:

scoreboard objectives add invert dummy

(run at start) then:

scoreboard players set FakePlayer invert 1

(impulse unconditional repeat) chained into:

execute at @e[tag=summoned] run scoreboard players reset FakePlayer invert

(chain unconditional repeat) chained into:

execute if score FakePlayer invert = 1 invert run say "All summoned animals are dead!"

This should reset FakePlayers score continuously until all entities with tag "summoned" are dead, then it should run the final condition. This does not happen, and I can't see why.


Solution 1:

There's a much easier way to do this in 1.13, thanks to the unless execute subcommand. The following should work:

execute unless entity @e[tag=summoned] run say "All summoned animals are dead!"

For performance, including a limit=1 will let it stop searching as soon as it finds one entity that matches:

execute unless entity @e[tag=summoned,limit=1] run say "All summoned animals are dead!"