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

Objectives ​

An Objective is a scoreboard objective. dp.objective(name) returns the same object every time, so modules can share one.

ts
const game = dp.objective("game"); // dummy
const home = dp.objective("home", "trigger");
KindChanged by
"dummy" (default)your commands only
"trigger"the player, via /trigger
`minecraft.${string}`a vanilla statistic

Redeclaring a name with a different kind throws.

Read and write scores ​

obj.score(holder) takes a Selector or a ScoreTarget fake player like #round (use # to hide it from the sidebar).

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

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

dp.createFunction("load").build(() => {
  game.score(ScoreTarget("#round")).set(0);
});

dp.createFunction("tick").build(() => {
  game.score(Selector.allPlayers()).add(1);
});

Open in playground

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

txt
scoreboard players set #round game 0
txt
scoreboard players add @a game 1
json
{
  "values": [
    "game:load"
  ]
}
json
{
  "values": [
    "game:tick"
  ]
}
txt
{
  "pack": {
    "description": "game\nCreated using Helix",
    "min_format": [
      107,
      1
    ],
    "max_format": [
      107,
      1
    ]
  }
}

TIP

dp.objective creates it at load. A new Objective(...) isn't registered; call obj.init() in a load function.

Let players set a score ​

Enable a trigger objective per player, read it next tick, then enable it again.

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

const dp = new Datapack("menu", v26_2);
const home = dp.objective("home", "trigger");

dp.createFunction("setup").build(() => {
  home.score(Selector.allPlayers()).enable();
});

dp.createFunction("poll").build((ctx) => {
  ctx.if(home.score(Selector.self()).greaterThan(0), (c) => {
    c.tellraw(Selector.self(), "teleporting home...");
  });
});

Open in playground

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

txt
scoreboard players enable @a home
txt
execute if score @s home matches 1.. run tellraw @s {"text":"teleporting home..."}
txt
{
  "pack": {
    "description": "menu\nCreated using Helix",
    "min_format": [
      107,
      1
    ],
    "max_format": [
      107,
      1
    ]
  }
}

Detect right-clicks ​

An objective on usedStatCriteria(item) counts uses of that item. Reset it each tick; >= 1 means it was used.

TIP

For player events, an advancement trigger costs nothing when idle.

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.