add while loop and member access
This commit is contained in:
parent
0d432e8bc7
commit
b6c6dcc0f4
|
|
@ -0,0 +1,3 @@
|
|||
onlyBuiltDependencies:
|
||||
- esbuild
|
||||
- sharp
|
||||
|
|
@ -330,6 +330,35 @@ arr[1] = 2;
|
|||
|
||||
Read more in the [reference](../../reference/variables).
|
||||
|
||||
## Loops
|
||||
!since[0.2.0]
|
||||
|
||||
While loops can be used to execute commands multiple times.
|
||||
The entire loop takes place within a single game-tick.
|
||||
For running commands every tick, the `#[tick]` annotation should be used on a function.
|
||||
|
||||
```shulkerscript
|
||||
while ("entity @p") {
|
||||
/say @p
|
||||
}
|
||||
```
|
||||
|
||||
Compile-time conditions will be expanded at compile-time into a list of commands without requiring logic in Minecraft.
|
||||
|
||||
```shulkerscript
|
||||
val x = 0;
|
||||
while (x < 3) {
|
||||
run `say $(x)`;
|
||||
x = x + 1;
|
||||
}
|
||||
```
|
||||
This will become
|
||||
```mcfunction
|
||||
say 0
|
||||
say 1
|
||||
say 2
|
||||
```
|
||||
|
||||
## Run
|
||||
The `run` keyword is used to evaluate the following expression and include the resulting command in the output.
|
||||
```shulkerscript
|
||||
|
|
@ -347,4 +376,12 @@ run lua() {
|
|||
-- Lua code goes here
|
||||
return "Hello, Lua!";
|
||||
};
|
||||
```
|
||||
```
|
||||
|
||||
## Member Access
|
||||
!since[0.2.0]
|
||||
|
||||
Additional properties of values can be accessed via member access (or dot notation).
|
||||
For example, `.length` gets the length of a string.
|
||||
Additional information about variable member access can be found in the [variable reference](../../reference/variables).
|
||||
If you need the actual name of the macro used in a function, you can get it with `.name`.
|
||||
|
|
@ -26,6 +26,8 @@ int myScore[];
|
|||
myScore["@p"] = 42;
|
||||
```
|
||||
|
||||
The scoreboard objective can be accessed with `myInt.objective` and the target/targets with `myInt.target`/`myInts.targets`.
|
||||
|
||||
### Operations
|
||||
|
||||
You can perform operations on integer variables, such as addition, subtraction, multiplication, and division.
|
||||
|
|
@ -53,4 +55,6 @@ bool manyBools[5] = [true, false, true, false, true];
|
|||
|
||||
// Create an entity-boolean map/tag and set the value of the nearest player to true at the same time
|
||||
bool myScore["@p"] = true;
|
||||
```
|
||||
```
|
||||
|
||||
The tag or storage name can be accessed with `myBool.name` and the storage path with `myBools.path`.
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
"patterns": [
|
||||
{
|
||||
"name": "keyword.control.flow.shulkerscript",
|
||||
"match": "\\b(if|else|return|group)\\b"
|
||||
"match": "\\b(if|else|return|group|while)\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -184,7 +184,7 @@
|
|||
"match": "^\\s*(/\\w+)(.*)$",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.other.commandliteral.shulkerscript"
|
||||
"name": "entity.name.function.commandliteral.shulkerscript"
|
||||
},
|
||||
"2": {
|
||||
"name": "string.command.shulkerscript"
|
||||
|
|
|
|||
Loading…
Reference in New Issue