Appearance
Scores
A Score is one scoreboard cell: an objective plus a holder.
ts
const game = dp.objective("game");
const total = game.score(ScoreTarget("total"));| Method | Emits |
|---|---|
.set(n) .add(n) .remove(n) .reset() | scoreboard players set/add/remove ... n |
.assign .plus .minus .times .divide .modulo .min .max .swap | scoreboard players operation ... |
.equal .greaterThan .lessThan | nothing; 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);
});Compiled output - the real files helix emits for the code above:
txt
scoreboard players add score game 1
scoreboard players operation score game += bonus gamejson
{
"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);
});
});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 0json
{
"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
- Math and
/compute: whole formulas - Score vectors: three scores as one vector
- Fixed-point numbers: fractions on top of a score
- Conditions