You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/variable/intermediate/bat_js.md
+27-27Lines changed: 27 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,28 @@
1
-
# Bat Cave: JavaScript
1
+
# Bat Cave: Blocks
2
2
3
3
## Step 1
4
-
Add an ``||player:on chat||`` command and name it**cave**.
4
+
Rename the existing ``||player:on chat||`` command **cave**.
5
5
6
-
```javascript
6
+
```blocks
7
7
player.onChat("cave", function () {
8
8
})
9
9
```
10
10
11
11
## Step 2
12
12
13
-
Code the player to ``||player:say||``by typing**"Dig a cave"**, and drag it into the ``||player:on chat||`` command.
13
+
Get a ``||player:player say||`` command, type**"Dig a cave"**, and drag it into the ``||player:on chat||`` command.
14
14
15
-
```javascript
15
+
```blocks
16
16
player.onChat("cave", function () {
17
17
player.say("Dig a cave")
18
18
})
19
19
```
20
20
21
21
## Step 3
22
22
23
-
Set the time of day to **day**.
23
+
Get a ``||gameplay:time set||`` block, set it **day**, and drag it into the ``||player:on chat||``**cave** command - below the ``||player:say||`` command.
24
24
25
-
```javascript
25
+
```blocks
26
26
player.onChat("cave", function () {
27
27
player.say("Dig a cave")
28
28
gameplay.timeSet(gameplay.time(DAY))
@@ -31,9 +31,9 @@ player.onChat("cave", function () {
31
31
32
32
## Step 4
33
33
34
-
Code the player to ``||blocks:fill with||`` an **air** block with these positions: **from = -1.0,-1** and **to = 1,2,1**. Code it to **replace**.
34
+
Get a ``||blocks:fill with||``block and select an **air** block with these positions: **from -1.0,-1** and **to 1,2,1**. Set it to **replace**.
35
35
36
-
```javascript
36
+
```blocks
37
37
player.onChat("cave", function () {
38
38
player.say("Dig a cave")
39
39
gameplay.timeSet(gameplay.time(DAY))
@@ -48,9 +48,9 @@ player.onChat("cave", function () {
48
48
49
49
## Step 5
50
50
51
-
Repeat the fill step **50** times.
51
+
Get a ``||loops:repeat||`` loop and set it to **50** times. Drag the ``||blocks:fill with||``**air** block into the loop, then drag the entire ``||loops:repeat||`` loop into the ``||player:on chat||``**cave** command below the ``||gameplay:time set||``**day** command.
52
52
53
-
```javascript
53
+
```blocks
54
54
player.onChat("cave", function () {
55
55
player.say("Dig a cave")
56
56
gameplay.timeSet(gameplay.time(DAY))
@@ -67,9 +67,10 @@ player.onChat("cave", function () {
67
67
68
68
## Step 6
69
69
70
-
Set a ``||variables:new variable||`` and name it **bat_cave**, then set that variable to the ``||player:player world position||``.
70
+
Get a ``||variables:set variable||`` and assign it a new variable called **bat_cave**. Get a ``||player:player world position||`` and drag it into the **bat_cave** variable.
71
+
Drag the newly completed ``||variables:set variable||``**bat_cave** into the ``||player:on chat||`` command **cave** below the ``||loops:repeat||`` loop **50**.
71
72
72
-
```javascript
73
+
```blocks
73
74
let batcave: Position = null
74
75
player.onChat("cave", function () {
75
76
player.say("Dig a cave")
@@ -88,53 +89,53 @@ player.onChat("cave", function () {
88
89
89
90
## Step 7
90
91
91
-
Code the player to ``||player:say||``“You have 10 seconds to go out before the bats arrive.”
92
+
Get a ``||player:say||``block and code it as "You have 10 seconds to go out before the bats arrive." Drag it into the ``||player:on chat||``**cave** command below the **bat_cave** variable.
92
93
93
-
```javascript
94
+
```blocks
94
95
player.say("You have 10 seconds to get out before the bats arrive.")
95
96
```
96
97
97
98
## Step 8
98
99
99
-
``||loops: Pause||``the code for **10** seconds (10,000 ms).
100
+
Get a ``||loops: pause||``loop and set it to **10** seconds (10,000 ms). Drag this loop into the end of the ``||player:on chat||`` command.
100
101
101
-
```javascript
102
+
```blocks
102
103
player.say("You have 10 seconds to get out before the bats arrive.")
103
104
loops.pause(10000)
104
105
player.on_chat("cave", on_chat)
105
106
```
106
107
107
108
## Step 9
108
109
109
-
After the pause, code the player to say “Watch out for bats!”.
110
+
Get another ``||player:player say||``command and code the player to say, "Watch out for bats!". Drag the newly completed ``||player:player say||`` into the ``||player:on chat||`` command at the end.
110
111
111
-
```spy
112
+
```blocks
112
113
loops.pause(10000)
113
114
player.say("Watch out for bats!")
114
115
player.on_chat("cave", on_chat)
115
116
```
116
117
117
118
## Step 10
118
119
119
-
Set the time to **dusk**.
120
+
Duplicate the ``||gameplay:time set||``**day** (from step 3) and set it to **dusk**. Drag it into the end of the ``||player:on chat||`` command.
120
121
121
-
```javascript
122
+
```blocks
122
123
gameplay.timeSet(gameplay.time(DUSK))
123
124
```
124
125
125
126
## Step 11
126
127
127
-
``||mobs:Spawn||``a bat at the **bat_cave** variable.
128
+
Get a ``||mobs:spawn animal||``block and drag it into the workspace, select **bat** and assign the **bat_cave** variable.
128
129
129
-
```javascript
130
+
```blocks
130
131
mobs.spawn(BAT, batcave)
131
132
```
132
133
133
134
## Step 12
134
135
135
-
Repeat the **bat**``||mobs:spawn animal||``**200** times.
136
+
Next, repeat the **bat**``||mobs:spawn animal||``step. Get a ``||loops:repeat||`` loop and set it to **200** times. Drag the **bat** into the loop. Drag the entire loop into the ``||player:on chat||``**cave** command below the ``||gameplay:time set||``**dusk** block.
136
137
137
-
```javascript
138
+
```blocks
138
139
for (let index = 0; index < 200; index++) {
139
140
mobs.spawn(BAT, batcave)
140
141
}
@@ -144,8 +145,7 @@ for (let index = 0; index < 200; index++) {
144
145
145
146
Go into Minecraft and type **cave** in the chat to see all the code run.
0 commit comments