Skip to content

Commit 62a6d40

Browse files
committed
added a swap function to trigger script
1 parent 62cc660 commit 62a6d40

2 files changed

Lines changed: 40 additions & 19 deletions

File tree

docs/TriggerScript.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
Trigger script allows you to code what a trigger should do when triggered with code.
1+
Trigger script allows you to code what a trigger should do when triggered with code.
22

33
## How it works
4+
45
Each line is a command with options following it. It is case insensitive.
56

67
## Commands
@@ -9,11 +10,11 @@ Each line is a command with options following it. It is case insensitive.
910

1011
alter a block's tileId (changing what block it is) or rotate a tile
1112

12-
#### Syntax:
13+
#### Syntax
1314

1415
`CHANGE <x> <y> BLOCK <tileId> ROTATE <rotation>`
1516

16-
#### Options:
17+
#### Options
1718

1819
`<x> <y>` - the position of the block to be altered
1920

@@ -27,27 +28,27 @@ alter a block's tileId (changing what block it is) or rotate a tile
2728

2829
teleport to a given position
2930

30-
#### Syntax:
31+
#### Syntax
3132

3233
`TELEPORT <x> <y> INSTANT`
3334

34-
#### Options:
35+
#### Options
3536

3637
`<x> <y>` - where to teleport the player
3738

3839
`INSTANT` - Include to make the teleport instant
3940

40-
---
41+
---
4142

4243
### DELAY
4344

4445
wait a specified amount of milliseconds
4546

46-
#### Syntax:
47+
#### Syntax
4748

4849
`DELAY <ms>`
4950

50-
#### Options:
51+
#### Options
5152

5253
`<ms>` - how long to delay in milliseconds
5354

@@ -57,23 +58,23 @@ wait a specified amount of milliseconds
5758

5859
fill a selection for `(x1, y1)` to `(x2, y2)`
5960

60-
#### Syntax:
61+
#### Syntax
6162

6263
`FILL <x1> <y1> <x2> <y2> BLOCK <tileId>`
6364

64-
#### Options:
65+
#### Options
6566

6667
`<x1> <y1> <x2> <y2>` - The start and end coordinates of where to fill
6768

6869
`BLOCK <tileId>` - Sets the tileId of the tile fill with
6970

70-
---
71+
---
7172

7273
### IF
7374

7475
check whether a statement is true and execute code
7576

76-
#### Syntax:
77+
#### Syntax
7778

7879
`IF BLOCK <x> <y> IS <property> <value>`
7980

@@ -85,29 +86,40 @@ check whether a statement is true and execute code
8586

8687
---
8788

88-
### ELSE
89+
### ELSE
8990

9091
specify what code to run after an if statement if the condition is false
9192

92-
#### Syntax:
93+
#### Syntax
9394

9495
`ELSE`
9596

96-
---
97+
---
9798

9899
### END
99100

100101
specifies the end for an if/else statement
101102

102-
#### Syntax:
103+
#### Syntax
103104

104105
`END`
105106

106-
---
107+
---
108+
109+
### SWAP
110+
111+
Toggles the red and blue blocks on and off
112+
113+
#### Syntax
114+
115+
`SWAP`
116+
117+
---
107118

108119
## Example Scripts
109120

110121
__Toggles a tile between ground and air__
122+
111123
```
112124
if block 2 9 is tileid 1 then
113125
change 2 9 block 0
@@ -117,23 +129,28 @@ end
117129
```
118130

119131
__Teleport to (1, 10)__
132+
120133
```
121134
teleport 1 10 instant
122135
```
123136

124137
__Fills from (1, 4) to (2, 5), waits half a second, then deletes it__
138+
125139
```
126140
fill 1 4 2 5 block 1
127141
delay 500
128142
fill 1 4 2 5 block 0
129143
```
130144

131145
__Changes block (1, 4) to tileId 4 and rotates it twice__
146+
132147
```
133148
change 1 4 block 4 rotate 2
134149
```
135150

136151
__Changes block (1, 5) to tileId 0 (air)__
152+
137153
```
138154
change 1 5 block 0
139-
```
155+
```
156+

frontend/javascript/trigger-script.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ export async function readTriggerScript(script) {
121121
step = { type: 'end' }
122122
execute.push(step)
123123
break
124+
case 'SWAP':
125+
step = {
126+
type: 'toggleBlocks'
127+
}
124128
default:
125129
throw new Error(`Unknown Command "${command}" at line ${i + 1}`)
126130
}
@@ -195,4 +199,4 @@ export function compileToTriggerScript(execute) {
195199
out += `${line}\n`
196200
}
197201
return out
198-
}
202+
}

0 commit comments

Comments
 (0)