Appearance
Conditions
ctx.if(condition, body) runs body when the condition holds. Chain .elif and .else.
ts
ctx.if(hp.atMost(4), (c) => c.say("low")).else((c) => c.say("ok"));| Condition | Checks |
|---|---|
score.equal(n) .greaterThan .lessThan .atLeast .atMost .matches(range) | a score against a number |
a.greaterThan(b) (both scores) | two scores |
Detect.entity(sel) / Detect.noEntity(sel) | an entity exists / doesn't |
Detect.block(pos, block) | a block at a position |
Detect.predicate(ref) | a predicate |
and(a, b) or(a, b) not(a) | combinations |
Branch
Only one branch runs, even if a body changes the scores its condition read.
ts
import { Datapack, v26_2, Detect, Selector, Range, and, or } from "helix";
const dp = new Datapack("flow", v26_2);
const hp = dp.objective("hp").score(Selector.self());
const shield = dp.objective("shield").score(Selector.self());
dp.createFunction("tick").build((ctx) => {
const nobodyNear = Detect.noEntity(Selector.allPlayers().distance(new Range(undefined, 8)));
ctx
.if(and(hp.atMost(4), nobodyNear), (c) => c.say("fleeing"))
.elif(or(hp.lessThan(shield), shield.equal(0)), (c) => c.say("guarding"))
.else((c) => c.say("attacking"));
});Compiled output - the real files helix emits for the code above:
txt
execute if score @s hp matches ..4 unless entity @a[distance=..8,limit=1] run return run say fleeing
execute if score @s hp < @s shield run return run say guarding
execute if score @s shield matches 0 run return run say guarding
say attackingtxt
function flow:zzzprivate/tick/if_0_chainjson
{
"values": [
"flow:tick"
]
}txt
{
"pack": {
"description": "flow\nCreated using Helix",
"min_format": [
107,
1
],
"max_format": [
107,
1
]
}
}Match many values
ctx.cases([[cond, body], ...]) is a flat elif chain. ctx.dispatchScore(score, ranges) picks a body by a score's value, using a binary search past 8 cases.