实验性实验性记分项名称。
可选displayName: string记分项的显示名称。
创建的记分项对象。
import { world, DisplaySlotId, ObjectiveSortOrder, DimensionLocation } from "@minecraft/server";
function updateScoreboard(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
const scoreboardObjectiveId = "scoreboard_demo_objective";
const scoreboardObjectiveDisplayName = "Demo Objective";
const players = world.getPlayers();
// Ensure a new objective.
let objective = world.scoreboard.getObjective(scoreboardObjectiveId);
if (!objective) {
objective = world.scoreboard.addObjective(scoreboardObjectiveId, scoreboardObjectiveDisplayName);
}
// get the scoreboard identity for player 0
const player0Identity = players[0].scoreboardIdentity;
if (player0Identity === undefined) {
log("Could not get a scoreboard identity for player 0.");
return -1;
}
// initialize player score to 100;
objective.setScore(player0Identity, 100);
world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.Sidebar, {
objective: objective,
sortOrder: ObjectiveSortOrder.Descending,
});
const playerScore = objective.getScore(player0Identity) ?? 0;
// score should now be 110.
objective.setScore(player0Identity, playerScore + 10);
}
实验性显示位置。
先前正显示的记分项,为空时返回 null。
清除显示位置上正在显示的记分项。
Clears the objective that occupies a display slot.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
实验性记分项名称。
Identifier of the objective.
指定的记分项对象。不存在时返回 null。
实验性显示位置。
位于指定显示位置的记分项显示配置。为空时返回 null。
实验性所有记分项对象组成的数组。
实验性所有分数持有者对象组成的数组。
实验性记分项对象或名称。
总是返回 true。
实验性显示位置。
记分项显示配置。
显示位上先前显示的记分项对象。先前未显示记分项时,返回 undefined。
Returns the previous ScoreboardObjective set at the
display slot, if no objective was previously set it returns
undefined.
设置指定的显示位置显示的记分项与其他显示配置。
Sets an objective into a display slot with specified additional display settings.
无法在只读模式下调用此函数,详见 WorldBeforeEvents。
表示记分板。其上包含了记分项和分数持有者。
Contains objectives and participants for the scoreboard.
示例: updateScoreboard.ts