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

Execute chains ​

ctx.execute() builds a raw execute ... run ... chain, one clause per method in call order.

TIP

Prefer ctx.if, sel.forEach and the other helpers. Use ctx.execute() for ported packs or store maths.

ContextClause
.as(sel) / .at(sel)as / at
.positioned(pos) / .positionedAs(sel)positioned / positioned as
.rotatedAs(sel)rotated as
.facing(pos) / .facingEntity(sel, anchor)facing / facing entity
.anchored(EntityAnchor.EYES)anchored
.in(dim) / .align(axes)in / align
Guard (each has an unless... twin)Clause
.ifEntity(sel)if entity
.ifBlock(pos, block)if block
.ifScoreMatches(score, range)if score ... matches
.ifScore(a, op, b)if score ... <op> ...
.ifPredicate(ref)if predicate
.ifItems(sel, slot, item)if items entity
StoreClause
.storeResultScore(score) / .storeSuccessScore(score)store result|success score
.storeResultStorage(id, path, type, scale)store result storage

Chain clauses ​

A one-command body inlines into run; a longer one becomes its own function.

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

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

dp.createFunction("standing_on_gold").build((ctx) => {
  ctx
    .execute()
    .as(Selector.allPlayers())
    .at(Selector.self())
    .ifBlock(Pos.rel(0, -1, 0), Block.GOLD_BLOCK)
    .ifScoreMatches(game.score(Selector.self()), new Range(1, undefined))
    .run((c) => c.say("standing on gold"));
});

Open in playground

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

txt
execute as @a at @s if block ~ ~-1 ~ minecraft:gold_block if score @s game matches 1.. run say standing on gold
txt
{
  "pack": {
    "description": "gameplay\nCreated using Helix",
    "min_format": [
      107,
      1
    ],
    "max_format": [
      107,
      1
    ]
  }
}

Store a result ​

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

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

dp.createFunction("count").build((ctx) => {
  ctx
    .execute()
    .storeResultScore(game.score(ScoreTarget("#players")))
    .run((c) => c.say("counting"));
});

Open in playground

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

txt
execute store result score #players game run say counting
txt
{
  "pack": {
    "description": "gameplay\nCreated using Helix",
    "min_format": [
      107,
      1
    ],
    "max_format": [
      107,
      1
    ]
  }
}

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.