Students give a function a parameter, so each call hands in a value and the same job is done differently each time.
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 9 min · Mix it up 3 min · Make 8 min · Aquarium 3 min
A parameter is an input to a function, such as speed in spawnEnemy(speed): the call hands in a number (spawnEnemy(50)), and inside the function speed is that number. So one function can make a slow bug and a fast bug. In the block editor, click Add a parameter when making the function; drag speed out of the function's header to use it inside. The common slip is typing a number inside the function, which ignores every call's value.
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 has a card: "walk across at ___ steps a second". The class calls a number; the student walks at that speed.
The card is the function; the number called out is the parameter.
Where the value comes from. Ask them to point at the call, then at where speed is used inside.
| What you will see | A question to ask | The fix |
|---|---|---|
| Every bug has the same speed. | Is speed used inside the function, or a number? | Drag speed from the function header into set vx. |
| The call has no slot for a number. | Did you add a parameter to the function? | Click the function header, Add a parameter, Number. |
| Only one kind of bug appears. | What numbers do your two calls hand in? | Use different numbers in the two calls: 30 and 90. |
One possible solution for each task. Other correct programs are fine.

let bug: Sprite = null
function spawnEnemy (speed: number) {
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 = speed
}
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 () {
spawnEnemy(randint(20, 100))
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
otherSprite.destroy()
info.changeLifeBy(-1)
})

let bug: Sprite = null
function spawnEnemy (speed: number, height: number) {
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, height)
bug.vx = speed
}
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 () {
spawnEnemy(randint(20, 100), randint(10, 110))
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
otherSprite.destroy()
info.changeLifeBy(-1)
})

let bug: Sprite = null
function spawnEnemy (speed: number) {
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 = speed
}
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 () {
spawnEnemy(30)
})
game.onUpdateInterval(3000, function () {
spawnEnemy(90)
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
otherSprite.destroy()
info.changeLifeBy(-1)
})
Open task: any program that does what the step asks.
Stretch: Add a third parameter for how many points the bug is worth when it is made, and give the fast bugs more.
Support: Give students one timer already calling spawnEnemy(30), and ask them to add the second.
spawnEnemy(speed) sets bug vx to speed. The timer calls spawnEnemy(70). How fast is that bug?
70. speed is the number the call handed in.
Next unit: gravity and jumping. Skillmap: the Game Maker Guide (arcade.makecode.com/skillmaps).