Alpha: this compiler is under active development and updates will break your projects. Not recommended for real use yet.
Skip to content

Scores ​

A Score is one scoreboard cell: an objective plus a holder.

ts
const game = dp.objective("game");
const total = game.score(ScoreTarget("total"));
MethodEmits
.set(n) .add(n) .remove(n) .reset()scoreboard players set/add/remove ... n
.assign .plus .minus .times .divide .modulo .min .max .swapscoreboard players operation ...
.equal .greaterThan .lessThannothing; returns a condition

Change a score ​

Use add/set with a number and plus/times/... with another score. Calls emit into the callback you're inside, so there's no ctx to pass.

ts
import { Datapack, v26_2, ScoreTarget } from "helix";

const dp = new Datapack("scores", v26_2);
const game = dp.objective("game");

const tick = dp.createFunction("tick");
tick.build((ctx) => {
  const score = game.score(ScoreTarget("score"));
  const bonus = game.score(ScoreTarget("bonus"));

  score.add(1);
  score.plus(bonus);
});

Open in playground

Compiled output - the real files helix emits for the code above:

txt
scoreboard players add score game 1
scoreboard players operation score game += bonus game
json
{
  "values": [
    "scores:tick"
  ]
}
txt
{
  "pack": {
    "description": "scores\nCreated using Helix",
    "min_format": [
      107,
      1
    ],
    "max_format": [
      107,
      1
    ]
  }
}

TIP

Operation verbs chain (acc.times(k).plus(delta)), one command each. For a formula with nested terms, use math`...`.

Branch on a score ​

Comparisons return a condition for ctx.if. They take a number or another score.

ts
import { Datapack, v26_2, ScoreTarget } from "helix";

const dp = new Datapack("scores", v26_2);
const game = dp.objective("game");

const tick = dp.createFunction("tick");
tick.build((ctx) => {
  const score = game.score(ScoreTarget("score"));
  ctx.if(score.greaterThan(100), () => {
    score.set(0);
  });
});

Open in playground

Compiled output - the real files helix emits for the code above:

txt
execute if score score game matches 101.. run scoreboard players set score game 0
json
{
  "values": [
    "scores:tick"
  ]
}
txt
{
  "pack": {
    "description": "scores\nCreated using Helix",
    "min_format": [
      107,
      1
    ],
    "max_format": [
      107,
      1
    ]
  }
}

Store a command's result ​

ctx.execute().storeResultScore(score).run(...) writes a count or query into a score. See Execute chains.

See also ​

Released under the MIT License · Credits
These docs were written with AI; the layout and every page have been reviewed by a human.