Students get a list of every sprite of a kind with array of sprites of kind, and use a for element loop to do something to each one.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 7 min · Investigate 10 min · Modify 8 min · Mix it up 3 min · Make 8 min · Fireworks 4 min
A list (an array in MakeCode) is many values in order under one name. array of sprites of kind Enemy (Sprites) is a list of every enemy in the game right now. A for element loop (Loops; MakeCode calls it "for element value of list") runs its blocks once for each item, with value standing for that item each time. That is how one button press can reach sprites that have no names. Blocks inside the loop run once per sprite; blocks after it run once.
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
The teacher says "for each student wearing blue: stand up and clap". Then "for each student wearing blue: stand up. Then clap once."
The first claps once per student; the second claps once in all. Inside the loop, and after it.
Which blocks go inside the loop. Ask: should this happen once, or once for each alien?
| What you will see | A question to ask | The fix |
|---|---|---|
| The smart bomb only scores 1, however many aliens there were. | Is change score inside the loop, or after it? | Inside the loop it runs once per alien. Drag it inside, under destroy value. |
| Nothing happens when B is pressed. | Which kind does array of sprites of kind name? | Choose Enemy in its dropdown. |
| The loop's value block is missing. | Where does value come from? | Drag value out of the for element block itself. |
One possible solution for each task. Other correct programs are fine.

scene.setBackgroundColor(15)
let ship = sprites.create(img`
. . 1 . .
. 1 1 1 .
1 1 1 1 1
`, SpriteKind.Player)
ship.setPosition(80, 110)
controller.moveSprite(ship, 100, 0)
game.onUpdateInterval(1000, function () {
let alien = sprites.create(img`
. 7 . 7 .
7 7 7 7 7
7 f 7 f 7
. 7 . 7 .
`, SpriteKind.Enemy)
alien.setPosition(randint(10, 150), 0)
alien.vy = 20
})
controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
for (let value of sprites.allOfKind(SpriteKind.Enemy)) {
value.vy = 0
value.y = 0
}
})

scene.setBackgroundColor(15)
let ship = sprites.create(img`
. . 1 . .
. 1 1 1 .
1 1 1 1 1
`, SpriteKind.Player)
ship.setPosition(80, 110)
controller.moveSprite(ship, 100, 0)
game.onUpdateInterval(1000, function () {
let alien = sprites.create(img`
. 7 . 7 .
7 7 7 7 7
7 f 7 f 7
. 7 . 7 .
`, SpriteKind.Enemy)
alien.setPosition(randint(10, 150), 0)
alien.vy = 20
})
controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
for (let value of sprites.allOfKind(SpriteKind.Enemy)) {
value.vy = 0
value.y = 0
}
})
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
for (let value of sprites.allOfKind(SpriteKind.Enemy)) {
value.vy = 40
}
})

scene.setBackgroundColor(15)
let ship = sprites.create(img`
. . 1 . .
. 1 1 1 .
1 1 1 1 1
`, SpriteKind.Player)
ship.setPosition(80, 110)
controller.moveSprite(ship, 100, 0)
game.onUpdateInterval(500, function () {
let alien = sprites.create(img`
. 7 . 7 .
7 7 7 7 7
7 f 7 f 7
. 7 . 7 .
`, SpriteKind.Enemy)
alien.setPosition(randint(10, 150), 0)
alien.vy = 20
})
controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
for (let value of sprites.allOfKind(SpriteKind.Enemy)) {
value.destroy()
info.changeScoreBy(1)
}
})
Open task: any program that does what the step asks.
Stretch: Make a magnet on A+B: every Food sprite flies towards the player (set value vx and vy, or use follow).
Support: Give students the on B pressed block with an empty for element loop already in it, and ask them only to choose the list and fill the loop.
There are 5 enemies on the screen. A for element loop over array of sprites of kind Enemy contains change score by 1. How much does the score go up?
By 5. The list has 5 enemies, and the loop runs its blocks once for each one.
Next lesson: functions, which name a job such as 'make an enemy' so it can be used in many places. Skillmap: Save the Galaxy (arcade.makecode.com/skillmaps) is a Galaga-style shooter that practises projectiles and enemies.