Students name a job (making an enemy) as a function, call it from several places, and see in Python that every event block is a function the game calls.
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 9 min · Snow globe 3 min
A function is a named job: some blocks with a name, made once in Functions (under Advanced in the toolbox). Making it does not run it. It runs when a call block calls it, once per call. One copy serves every call, so a change to the function changes every place that calls it. The Python button at the top of the editor shows the same program as text: every event block (on game update every, on overlap, on A pressed) becomes a def, handed to the game, which calls it. MakeCode adds a global bug line inside the function: it means "use the bug variable from outside". Parameters (inputs) are next lesson.
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.
One student holds a recipe card ("make a bug: stand at the door, walk across"). Nothing happens until the teacher calls "make a bug!", and then it happens each time.
Writing the card is making the function; calling its name runs it.
Show your coin collector to the next pair. Collect a coin: does a new one appear?
Making a function does nothing until it is called. When nothing appears, ask which block calls the function.
| What you will see | A question to ask | The fix |
|---|---|---|
| No bugs appear. | Which block calls your function? | Add a call block (from Functions) inside the timer or on start. |
| The call block is missing from the toolbox. | Have you made the function yet? | Make the function first; its call block then appears under Functions. |
| Only one coin ever comes back. | Where is the call to makeCoin in the overlap? | Call it after destroy, inside the Player–Food overlap. |
One possible solution for each task. Other correct programs are fine.

let bug: Sprite = null
function spawnBug () {
bug = sprites.create(img`
. . 7 7 . .
. 7 7 7 7 .
7 7 f 7 f 7
. 7 7 7 7 .
`, SpriteKind.Enemy)
bug.setPosition(0, randint(10, 110))
bug.vx = 40
info.changeScoreBy(1)
}
info.setLife(3)
let player = sprites.create(img`
. 4 4 .
4 4 4 4
. 8 8 .
. 8 8 .
`, SpriteKind.Player)
player.setPosition(140, 60)
controller.moveSprite(player)
player.setStayInScreen(true)
game.onUpdateInterval(1000, function () {
spawnBug()
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
otherSprite.destroy()
info.changeLifeBy(-1)
})

let bug: Sprite = null
function spawnBug () {
bug = sprites.create(img`
. . 7 7 . .
. 7 7 7 7 .
7 7 f 7 f 7
. 7 7 7 7 .
`, SpriteKind.Enemy)
bug.setPosition(0, randint(10, 110))
bug.vx = 40
info.changeScoreBy(1)
}
info.setLife(3)
let player = sprites.create(img`
. 4 4 .
4 4 4 4
. 8 8 .
. 8 8 .
`, SpriteKind.Player)
player.setPosition(140, 60)
controller.moveSprite(player)
player.setStayInScreen(true)
game.onUpdateInterval(1000, function () {
spawnBug()
})
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
spawnBug()
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
otherSprite.destroy()
info.changeLifeBy(-1)
})

let coin: Sprite = null
function makeCoin () {
coin = sprites.create(img`
. 5 5 .
5 5 4 5
5 4 5 5
. 5 5 .
`, SpriteKind.Food)
coin.setPosition(randint(10, 150), randint(10, 110))
}
scene.setBackgroundColor(7)
let player = sprites.create(img`
. 4 4 .
4 4 4 4
. 8 8 .
. 8 8 .
`, SpriteKind.Player)
controller.moveSprite(player)
player.setStayInScreen(true)
makeCoin()
makeCoin()
makeCoin()
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
otherSprite.destroy()
info.changeScoreBy(1)
makeCoin()
})
Open task: any program that does what the step asks.
Stretch: Make a second function, makeSpike, that adds an Enemy at a random place, and call it every 3 seconds.
Support: Give students the makeCoin function already made, and ask them to add the four calls.
You make a function, but never call it. What happens when the game runs?
Nothing from that function: its blocks only run when something calls it.
Next lesson: a parameter, so one function can make a slow bug and a fast bug. Skillmap: the Game Maker Guide (arcade.makecode.com/skillmaps) builds bigger games from named jobs like these.