Docs / Language
Scores
namespace demo;
var #mana = 0;
mcfun regen() { if (@s.#mana < 100) { @s.#mana = @s.#mana + 5; }}A # variable is a scoreboard score: a 32-bit integer. Math wraps on overflow, and / and % round down.
- A global
#manahas its owndummyobjective,<namespace>.mana, whichpoplar/loadadds. #manaon its own is the global value, held by the fake player#global. The sidebar hides it.@s.#manais an entity’s value in the same objective. Any selector works:@p.#mana,@a.#mana.- A local is the fake player
#<name>_<function>in the objectivepoplar.<namespace>.
Scores support + - * / % and the comparisons < <= > >= == !=. The example above compiles to one command:
execute if score @s demo.mana matches ..99 run scoreboard players add @s demo.mana 5To read an entity score, the selector must name one entity: @s, @p, @r, @n, or a selector with limit=1. You can write to many entities at once (@a.#mana = 0;).
Costs and caveats
- Each global
#variable adds one objective to the world. /reloadkeeps values. A global’s initial value is only set when#globalhas no value, so changing it in your code doesn’t change an existing world. Entities get no initial value.- A local costs one command per declaration to set its value. Locals have no entity values, so
@s.#iis an error when#iis local.
MIT licensed. The standard library is MIT-0.Not an official Minecraft product. Not approved by or associated with Mojang or Microsoft.