世界修改
记分项名称。
可选
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);
}
记分项名称。
Identifier of the objective.
指定的记分项对象。不存在时返回 null
。
显示位置。
位于指定显示位置的记分项显示配置。为空时返回 null
。
世界修改
显示位置。
记分项显示配置。
显示位上先前显示的记分项对象。先前未显示记分项时,返回 undefined
。
Returns the previous ScoreboardObjective
set at the
display slot, if no objective was previously set it returns
undefined
.
表示记分板。其上包含了记分项和分数持有者。
Contains objectives and participants for the scoreboard.
示例: updateScoreboard.ts