完整版BedrockWiki镜像!
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Scoreboard Operations
|
||||
category: General
|
||||
title: 记分板操作
|
||||
category: 基础
|
||||
mentions:
|
||||
- Sprunkles137
|
||||
- Luthorius
|
||||
@@ -8,128 +8,131 @@ mentions:
|
||||
- Hatchibombotar
|
||||
---
|
||||
|
||||
Scoreboards can be used to perform complex operations, similar to [Molang](/concepts/molang). Operations come in two flavors: mathematical, and logical.
|
||||
# 记分板操作
|
||||
|
||||
## Overview
|
||||
Operations are performed using the `/scoreboard players operation` command. The full syntax is laid out below:
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
记分板可用于执行复杂运算,其功能类似于[Molang](/wiki/concepts/molang)。运算分为两类:数学运算和逻辑运算。
|
||||
|
||||
## 概述
|
||||
使用`/scoreboard players operation`命令执行运算。完整语法如下:
|
||||
```
|
||||
/scoreboard players operation <targetScore> <objective> <operation> <sourceScore> <objective>
|
||||
/scoreboard players operation <目标分数> <记分项> <运算符> <源分数> <记分项>
|
||||
```
|
||||
The command consists of two score holders: The target score, and the source score. The target score is the value being operated on, and the source score is the value affecting the operation. The result of the operation is written into the target score, and the source score's value is not touched, save for [one operation](/commands/scoreboard-operations#swap-operator).
|
||||
该命令包含两个分数持有者:目标分数和源分数。目标分数是被操作的值,源分数是参与运算的值。运算结果将写入目标分数,源分数的值不会被修改(除[交换运算符](/wiki/commands/scoreboard-operations#swap-operator)外)。
|
||||
|
||||
## Mathematical Operators
|
||||
Mathematical operators use arithmetic to affect the target score. There are five mathematical operations available: addition, subtraction, multiplication, floor division, and floor modulo division.
|
||||
## 数学运算符
|
||||
数学运算符通过算术运算影响目标分数。共有五种数学运算:加法、减法、乘法、向下取整除法和向下取整模除。
|
||||
|
||||
For each of the following examples below, assume that score holder `A var` equals 25, and `B var` equals 10.
|
||||
以下示例均假设分数持有者`A var`的值为25,`B var`的值为10。
|
||||
|
||||
### Addition
|
||||
Operator: **+=**
|
||||
### 加法
|
||||
运算符:**+=**
|
||||
|
||||
This operation adds the target score and source scores together, then stores the sum into the target score.
|
||||
将目标分数与源分数相加,结果存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var += B var
|
||||
```
|
||||
`A = A + B`, and as such `25 + 10 = 35`.
|
||||
即`A = A + B`,运算结果为`25 + 10 = 35`。
|
||||
|
||||
### Subtraction
|
||||
Operator: **-=**
|
||||
### 减法
|
||||
运算符:**-=**
|
||||
|
||||
This operation subtracts the target score by the source score, then stores the difference into the target score.
|
||||
从目标分数中减去源分数,结果存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var -= B var
|
||||
```
|
||||
`A = A - B`, and as such `25 - 10 = 15`.
|
||||
即`A = A - B`,运算结果为`25 - 10 = 15`。
|
||||
|
||||
### Multiplication
|
||||
Operator: **\*=**
|
||||
### 乘法
|
||||
运算符:***=**
|
||||
|
||||
This operation multiplies the target score by the source score, then stores the product into the target score.
|
||||
将目标分数乘以源分数,结果存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var *= B var
|
||||
```
|
||||
`A = A * B`, and as such `25 * 10 = 250`.
|
||||
即`A = A * B`,运算结果为`25 * 10 = 250`。
|
||||
|
||||
### Floored Division
|
||||
Operator: **/=**
|
||||
### 向下取整除法
|
||||
运算符:**/=**
|
||||
|
||||
This operation divides the target score by the source score, then stores the quotient into the target score. Because score values can only be integers, the value is floored, or rounded down.
|
||||
将目标分数除以源分数,结果向下取整后存入目标分数(由于分数值只能是整数)。
|
||||
```
|
||||
/scoreboard players operation A var /= B var
|
||||
```
|
||||
`A = floor(A / B)`, and as such `floor(25 / 10) = 2`.
|
||||
即`A = floor(A / B)`,运算结果为`floor(25 / 10) = 2`。
|
||||
|
||||
### Floored Modulo Division
|
||||
Operator: **%=**
|
||||
### 向下取整模除
|
||||
运算符:**%=**
|
||||
|
||||
This operation also divides the target score by the source score, but instead returns the remainder after the division into the target score. This is also floored.
|
||||
将目标分数除以源分数后取余数,结果向下取整后存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var %= B var
|
||||
```
|
||||
`A = floor(mod(A, B))`, and as such `floor(mod(25, 10)) = 5`.
|
||||
即`A = floor(mod(A, B))`,运算结果为`floor(mod(25, 10)) = 5`。
|
||||
|
||||
## Logical Operators
|
||||
Logical operations use logic gates and assignments to affect the target score. There are four logical operations available: assignment, less than, greater than, and swap.
|
||||
## 逻辑运算符
|
||||
逻辑运算符使用逻辑门和赋值操作来影响目标分数。共有四种逻辑运算:赋值、最小值、最大值和交换。
|
||||
|
||||
Similar to the above, assume that score holder `A var` equals 25, and `B var` equals 10.
|
||||
同样假设分数持有者`A var`的值为25,`B var`的值为10。
|
||||
|
||||
### Assignment Operator
|
||||
Operator: **=**
|
||||
### 赋值运算符
|
||||
运算符:**=**
|
||||
|
||||
This operation sets the target score equal to the source score.
|
||||
将目标分数设置为源分数的值。
|
||||
```
|
||||
/scoreboard players operation A var = B var
|
||||
```
|
||||
`A = B`, and as such the result is `10`.
|
||||
即`A = B`,运算结果为`10`。
|
||||
|
||||
### Minimum Operator
|
||||
Operator: **<**
|
||||
### 最小值运算符
|
||||
运算符:**<**
|
||||
|
||||
This operation returns the smallest of the input scores, and stores it into the target score.
|
||||
比较两个分数后,将较小值存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var < B var
|
||||
```
|
||||
`A = min(A, B)`, and as such `min(25, 10) = 10`.
|
||||
即`A = min(A, B)`,运算结果为`min(25, 10) = 10`。
|
||||
|
||||
### Maximum Operator
|
||||
Operator: **>**
|
||||
### 最大值运算符
|
||||
运算符:**>**
|
||||
|
||||
This operation returns the largest of the input scores, and stores it into the target score.
|
||||
比较两个分数后,将较大值存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var > B var
|
||||
```
|
||||
`A = max(A, B)`, and as such `max(25, 10) = 25`.
|
||||
即`A = max(A, B)`,运算结果为`max(25, 10) = 25`。
|
||||
|
||||
### Swap Operator
|
||||
Operator: **><**
|
||||
### 交换运算符
|
||||
运算符:**><**
|
||||
|
||||
This operation swaps the target score and source scores with each other. This is the only operation that affects the source score.
|
||||
交换目标分数和源分数的值。这是唯一会影响源分数的运算符。
|
||||
```
|
||||
/scoreboard players operation A var >< B var
|
||||
```
|
||||
The above command would swap the values of A and B e.g.
|
||||
执行上述命令后,A和B的值将互换:
|
||||
|
||||
Before: A = 10; B = 25;
|
||||
执行前:A = 10;B = 25;
|
||||
|
||||
After: A = 25; B = 10;
|
||||
执行后:A = 25;B = 10;
|
||||
|
||||
This can be seen as three operations: `temp = A; A = B; B = temp;`, and as such `A var = 10` and `B var = 25`.
|
||||
该操作等效于三步操作:`temp = A; A = B; B = temp;`,最终`A var = 10`且`B var = 25`。
|
||||
|
||||
## Useful Creations
|
||||
## 实用案例
|
||||
|
||||
#### Check If Values are Equal
|
||||
#### 检查数值是否相等
|
||||
|
||||
If you want to check in scoreboard, whether one value equals another value, you can copy first value to temporary value, subtract the other and compare temporary value to zero. Given values A and B:
|
||||
若要通过记分板检查两个值是否相等,可将第一个值复制到临时变量,再减去第二个值后比较临时变量是否为0。假设有值A和B:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```
|
||||
::: code-group
|
||||
```json [实体标签]
|
||||
scoreboard objectives add temp dummy
|
||||
scoreboard players operation @e temp = @s A
|
||||
scoreboard players operation @e temp -= @s B
|
||||
execute @e[scores={temp=0}] ~~~ say A equals B
|
||||
execute @e[scores={temp=0}] ~~~ say A等于B
|
||||
scoreboard objectives remove temp
|
||||
```
|
||||
|
||||
#### Scoreboard Initialization
|
||||
#### 记分板初始化
|
||||
|
||||
If you want to initialize a scoreboard value to 0, but only if it doesn't exists, you can use `scoreboard players add <selector> <name> 0`. It will set the value to 0, if it doesn't exist on the entity and do nothing, if it already exist.
|
||||
若要将记分板值初始化为0(仅当该值不存在时),可使用`scoreboard players add <选择器> <名称> 0`。此命令会在实体不存在该分数时设为0,若已存在则不做任何操作。
|
||||
Reference in New Issue
Block a user