1

Optimising function code, executing by score

Zero_4793 3/15/20 4:34 am history
223
6/18/2020 10:19 am
Which is better?

1) execute as @s[​scores={VALUE=X}] run
2) execute if score @s VALUE matches X run
Posted by
Zero_4793
Level 56 : Grandmaster Technomancer
60

  Have something to say?

JoinSign in

7

One_Nose
06/18/2020 10:19 am
He/Him • Level 59 : Grandmaster Dragonborn Hero
if score is more readable and says what you mean.
1
Bertiecrafter
06/12/2020 12:54 pm
Level 72 : Legendary System
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
1
GParcade
04/04/2020 7:13 am
Level 30 : Artisan Explorer
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.
2
HoboMaggot
03/15/2020 5:12 am
Level 55 : Grandmaster Blob
/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>
1
Zero_4793
03/15/2020 5:25 pm
Level 56 : Grandmaster Technomancer
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.
1
HoboMaggot
03/16/2020 5:31 am
Level 55 : Grandmaster Blob
Pretty sure both of them have no difference, but the selector is faster to type out
2
Zero_4793
03/15/2020 4:34 am
Level 56 : Grandmaster Technomancer
I know that they do the same thing functionally, but within minecrafts internal code, is either option processed more efficiently?
1

Welcome