Activity: Sing a Song of Sixpence

“Sing a song of sixpence, A pocket full of rye.
Four and twenty blackbirds,
Baked in a pie.”
– English Nursery Rhyme

In this activity, students will take inspiration from an old English nursery rhyme, because old English nursery rhymes are super popular with young people these days. Right?

You will change it up just a little, though. Instead of blackbirds you will use parrots, and instead of pie you will use cake!

Do the activity

Check for broken blocks

  1. From ||blocks:Blocks||, drag ||blocks:on broken|| onto the coding Workspace. This will be your event handler.
blocks.onBlockBroken(blocks.block(Block.Grass), function () {

})

Go for the cake

  1. Using the drop-down menu, select the Cake item. Use that friendly search!

the searchbar is your friend

Spawn an animal

  1. From ||mobs:Mobs||, place ||mobs:spawn animal|| under the ||blocks:on broken|| block until you hear it snap into place.
blocks.onBlockBroken(blocks.block(Block.Cake), function () {
    mobs.spawn(mobs.animal(AnimalMob.Chicken), positions.create(0, 0, 0))
})

Make it a parrot

  1. From the drop-down menu in the ||mobs:spawn animal|| block, select a parrot.
  2. You want to spawn the parrots above your head, so in the ||mobs:spawn animal|| block, change the Y coordinate to 1.

pick the parrot mob

More parrots!

This will spawn only one parrot above your head, so let’s use a ||loops:repeat|| loop to spawn 24 parrots.

  1. From ||loops:loops||, place a ||loops:repeat|| loop around ||mobs:spawn animal||.

  2. In the ||loops:repeat|| loop, enter the number 24.

blocks.onBlockBroken(blocks.block(Block.Cake), function () {
    for (let i = 0; i < 24; i++) {
        mobs.spawn(mobs.animal(AnimalMob.Parrot), positions.create(0, 1, 0))
    }
})

Run the code

To run this in the game, add a cake to your player inventory (press E to open your inventory), select the cake in your toolbar (use the mouse wheel or the number keys), and right-click to place the cake on the ground.

Then change back to your hands and use the left mouse button to hit the cake to destroy it – you should see a flock of parrots appear!

parrots appear around the cake

Shared Program: https://makecode.com/_0ji3UvTDg4Ds

Challenges

Try the following challenges to get more practice with events.

Challenge 1 - Make Ocelots Appear

Change the existing code so five ocelots appear when you break grass blocks.

The ocelot is a wild cat native to the Southwestern United States, Mexico, and Central and South America.

Challenge 2 - Print “Broken” in TNT

Let’s change what happens when grass is broken. Now let’s print the word “broken” in TNT.

Use search to find print, and use these coordinates so the printing starts a bit away from you!

print broken coordinates

Experiments

Here there are no rules… Copy the code for the experiments and change things around to see what kind of results you can create. Suggestions are given, but do as you like!

Experiment 1 - AutoCake

Move a cake into your inventory automatically. You can run this in the game without manually adding a cake to your player inventory. What other things could you give yourself at start????

Use this code to start with.

Experiment 2 - Chained Events

Here you can see a chained event. You break cake to spawn parrots, and if you kill parrots you spawn skeleton horses. Can you make other cause-and-effect chains?

Use this code to start with.