1

I understand that to display a raw score in raw JSON text, the score component is used:

{"score":{"name":"@p"," objective":"test"}}

So I'm using the following command to set a zombie's custom name based on a score:

data modify entity @e[limit=1,type=zombie,sort=nearest] CustomName set value '{"score":{"name":"@e[limit=1,type=zombie,sort=nearest]","objective":"test"}}'

But unfortunately, this doesn't seem to display a score, even though I'm sure a score is instantiated.

What can I do to make this work?

1

The answer to this lies within JSON component resolution. The JSON parser needs to resolve the data before it is displayed. For example, when you type:

[{"text":"You have "},{"score":{"name":"@p"," objective":"test"}},{"text":" point(s)."}]

It needs to convert the score component into a text component containing the proper number:

[{"text":"You have "},{"text":"5"},{"text":" point(s)."}]

This conversion (called resolution) can only happen from commands, signs, and loot table functions. In order to resolve JSON text automatically, we need to use a sign, which will always resolve JSON text immediately.

This means we will need a sign in our world. The standard location for this sign is (−30000000, 0, 1603). This standard location was chosen because it is outside the world border so no one can interact with it, plus a few other factors1:

setblock -30000000 0 1603 oak_wall_sign[facing=south]

Then a command to put the JSON text onto the sign would look like:

data modify block -30000000 0 1603 Text1 set value '{"score":{"name":"@e[limit=1,type=zombie,sort=nearest]","objective":"test"}}'

Then we write that data:

data modify entity @e[limit=1,type=zombie,sort=nearest] CustomName set from block -30000000 0 1603 Text1

1: Only chunk that is outside the WB, easy to remember, last two digits are 0, isn't 0

1
  • Why is this a standard location, why not explain this is outside the world border – Ray Wu Mar 27 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.