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

Locals ​

ctx.let(init?) returns a scratch Score for the current function, so you never pick holder names.

ts
const distSq = ctx.let(math`${x} * ${x} + ${z} * ${z}`);

init can be a number, a score or a math`...` expression.

Use a local ​

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

const dp = new Datapack("flow", v26_2);
const x = dp.objective("x").score(Selector.self());
const z = dp.objective("z").score(Selector.self());

dp.createFunction("tick").build((ctx) => {
  const distSq = ctx.let(math`${x} * ${x} + ${z} * ${z}`);
  ctx.if(distSq.lessThan(100), (c) => c.say("close"));
});

Open in playground

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

txt
scoreboard players operation #tick.0 helix.var = @s x
scoreboard players operation #tick.0 helix.var *= @s x
scoreboard players operation #_t0 helix.var = @s z
scoreboard players operation #_t0 helix.var *= @s z
scoreboard players operation #tick.0 helix.var += #_t0 helix.var
execute if score #tick.0 helix.var matches ..99 run say close
json
{
  "values": [
    "flow:tick"
  ]
}
txt
{
  "pack": {
    "description": "flow\nCreated using Helix",
    "min_format": [
      107,
      1
    ],
    "max_format": [
      107,
      1
    ]
  }
}

WARNING

A recursive call reuses the caller's locals, and locals don't carry across ctx.wait.

Pass a value into a summon ​

A local is a fake player, so it stays readable inside a body that runs as another entity.

ts
const me = ctx.let(owner.score(ctx.self));
ctx.summon(Interaction({}), Pos.here(), (c) => owner.score(c.self).assign(me));

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.