Score Objectives
#
The basicsSandstone can handle the lifetime of scoreboard objectives for you. By calling Objective.create
, Sandstone will create the specified objective when the datapack loads, and will return an Objective
object with convenient methods. By calling Objective.get
, Sandstone will not create the objective, but will still return an Objective
object. This is useful when the objective has already been created outside of Sandstone.
#
Scores Holders#
The basicsIn Minecraft, scores can be applied to 2 kind of things : fake players, and entities. They are called Score Holders.
In Sandstone, to get the value of an objective for a given score holder, you can directly call the objective with the selector.
#
OperationsSandstone has a number of helper methods to perform operations on scores.
#
Inline operationsInline operations are operations that modify the base score. For example, myKills.add(2)
would compile in scoreboard players add @s kills 2
. The value of myKills
will change.
There is one inline method for each type of operations (+
, -
, ×
, ÷
), and they all accept numbers and other player scores:
There are two more inline operation:
- The
set
method. It sets the score to the given value, or player score. - The
swap
method. It takes another player's score as an argument, and swap both values.
Every operation returns the base score. Therefore, you can chain them:
#
Effect-free operationsEffect-free operations are operations that create a whole new score to store the result. Therefore, the base score is never updated.
For example, myKills.plus(2)
would compile in something like:
In other aspects, they are similar to inline operations: there is a method for each type of operation (+
, -
, ×
, ÷
), and they all accept a number or another player score:
#
MathematicsAll these operations can be chained together: they allow you to write complex operation without complexity.
Since the result of operations are another PlayerScore
, you can also chain comparisons after operations.
#
ComparisonScores are easy to compare against another value, and integrate perfectly with Sandstone's flow statements.
There are 5 comparison methods, that all accepts both a number or another player's score: lessOrEqualThan
, lessThan
, equalTo
, greaterOrEqualThan
, and greaterThan
.
You can use them in any flow statement: