mojira.dev
MC-133128

execute unless score

I conducted tests 1 and 2 on the ground and then all 3 tests 30 blocks up in the air just to make sure there were no entities around me.

 

Test 1

/execute unless score @e[distance=..5,limit=1] s1 = @s s1

Test passed

 

Test 2

/execute unless score @e[tag=place_holder,distance=..5,limit=1] s1 = @s s1

No entity was found

 

Test 3

/execute unless entity @e[tag=place_holder,distance=..5,limit=1]

Test passed

 

Expected results:
Test 1: Results are as expected, there is no entity in range so it should pass.
Test 2: If there is no entity then there can be no score, test should pass.
Test 3: Results are as expected, there is no entity in range so it should pass.

Comments 3

It could be argued that this is intended behavior, because if you're normally comparing scores, and there are no scores, then you don't want the thing to happen anyway.

for instance
/execute unless score @e[type=cows] numSpots >= @e[type=ocelot] numSpots run say "Cats have the most spots!"

in this case, if cows happened to have more spots than ocelots, you wouldnt want the message to run, since it's hard coded that cats have the most spots. Also, in the case that there are no ocelots, you would also not want the command to run since there are no cats to compare to cows.

I suppose that the behavior you hope to produce may be done another way than detecting the null entity

@Charlie Miller

Unless is meant to be the exact opposite of IF.

What I am saying is that everything works fine when using IF but when you try to use UNLESS, to do the same thing, it all goes wrong.

Test 1: Standing right next to my mate Fred the armor stand

/execute if score @e[name=Fred,distance=0..5,limit=1] pid = @s pid run msg Stuperfied matched1

Result - Stuperfied whispers to you: matched1

Test 2: Bye fred, im going now. *Walks 20 blocks away

/execute if score @e[name=Fred,distance=0..5,limit=1] pid = @s pid run msg Stuperfied matched1

Result - Dead Silence.....

Test 3: Standing right next to Fred again, i've returned with beer

/execute unless score @e[name=Fred,distance=0..5,limit=1] pid = @s pid run msg Stuperfied matched1

Result - Can't hear a thing, certainly not out of Fred. Oh well, i'll just keep this beer for myself

Test 4: Walks 20 blocks away from Fred

/execute unless score @e[name=Fred,distance=0..5,limit=1] pid = @s pid run msg Stuperfied matched1

Result - Hmm, still dead silence.

The described behavior in the description is as expected.
Test 1: Will find the player. It will not pass, if the player has set a score for s1 and will only pass otherwise. It might also pass, if there is another entity with a different score that happens to be found first by the default arbitary sort order.

Test 2: The semantic of that is "Execute the command, unless the first entity you find with the placeholder tag in a distance of 5 or lower has the same score as the executor". It does not mean "Execute the command unless you find an entity with matching selector arguments that has the same score as the executor". Since there is no entity that matches the selector, the test will fail.
Programming wise that is similar to asking a List if it is empty, but the List itself is a nullpointer. Is the none-existing list empty? In java for instance that would produce a NullPointerException in both cases. This is similar here. The feedback does not say "Test failed" it says "no entity found" as in "I can't execute the command, because there is nothing to compare against".
Test 2 would also fail, if there are 2 entities that match the selector, one has the same score, the other one doesn't and the one that does is found first.

Test 3 is as expected for the reason you provided.

Michael Hurt

(Unassigned)

Unconfirmed

Minecraft 1.13-pre6

Retrieved