1
Which is better?
1) execute as @s[scores={VALUE=X}] run
2) execute if score @s VALUE matches X run
1) execute as @s[scores={VALUE=X}] run
2) execute if score @s VALUE matches X run
7
if score is more readable and says what you mean.
I can't say for sure, but I think "if score" is faster, for the following reasons (that I can think of):
- You're not assigning @s again, which the "as" instruction does
- You don't need to parse the NBT/JSON style structure in the score= target selector argument
- There is no need to loop through an array of arguments even though it only contains the "scores=" argument
Again, I don't have proof though. And is performance really that important? I usually do the "@s[scores=]" style command because it's a little shorter XD
- You're not assigning @s again, which the "as" instruction does
- You don't need to parse the NBT/JSON style structure in the score= target selector argument
- There is no need to loop through an array of arguments even though it only contains the "scores=" argument
Again, I don't have proof though. And is performance really that important? I usually do the "@s[scores=]" style command because it's a little shorter XD
In fact, they are the same in performance because they both go through all the entities in the selector, the only difference is that "if" the next "execute" command passes only "flase" and "true" to the unlike "as" command, therefore it will be optimal only if you do not want to work with these entities, but if you use @s then "as" is already better because it is shorter.
/execute if score is more used for fake players and is useful for adventure maps. For example:
/execute if score $Lock matches 1 run <command>I realise this, and it is how i've mainly used it so far. but when running functions that are already executing as and at a target entity it seems out to execute as @s[criteria]
and my main concern is if either in that context are less performance heavy. Optimising is important when you plan to make large datapacks.
and my main concern is if either in that context are less performance heavy. Optimising is important when you plan to make large datapacks.
Pretty sure both of them have no difference, but the selector is faster to type out
I know that they do the same thing functionally, but within minecrafts internal code, is either option processed more efficiently?
