Programming with Minecraft

Ben Davies

Ben Davies is project manager for English at language learning app Babbel, developing innovative and effective English language learning courses for the Babbel app. Previously, Ben taught languages in Secondary schools in the UK, and English language courses to adults in Spain. The Babbel language learning app spans 14 different languages, with bite-sized lessons designed by language experts. 73% of surveyed customers feel that they’d be able to hold a conversation within five hours of using the app.

Follow @babbel

Website: www.babbel.com Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Children love programming. A simple statement, but one that my experience as a Primary school teacher and a Computing subject leader has provided me with a glut of evidence to support. Visual programming applications are commonplace in the vast majority of Primary schools, but what about those pupils who are eager to take the step and cross the divide into the world of text based coding. This can be a huge step and, due to the pedantic syntax requirements of text-based code, can risk disengaging pupils. However, by using a Raspberry Pi and Minecraft, we can offer them an engaging introduction to text programming.

Minecraft Pi is a stripped down version of the popular game, similar to the pocket-editions that run on various tablets. It comes installed on the popular Raspbian operating system and can be connected to Python 2 allowing children to write code that produces actions in the game. This allows children, after writing a small amount of code, to produce something with striking visual impact (certainly more than Hello World).

Essentials

Before children start hacking, they must ensure they have done the following: opened a Minecraft world and started playing the game (tab key will release the cursor from Minecraft Pi); opened Python 2; opened a new file from the Python shell. Once they have written their program, children need to save it (ALT+S) before running (F5).

Sequencing

The first activity addresses the need for programs to be sequenced correctly in order for them to achieve specific goals and involves children writing knock-knock jokes with appropriate delays between the lines of text. The code displayed, which is case sensitive, connects Python to Minecraft, imports the required modules for the program into Python and then posts each string (line of printable text) to the message chat area. By using the time.sleep() command children can create a delay between each message to allow sufficient time to read it.

Precise Language

Moving on, children gain an appreciation of the requirement for precise and unambiguous instructions and the use of predetermined vocabulary and syntax. Children learn how to place a block of red wool below the character’s feet by writing the following code.

First children can modify the colour of the wool by changing the number after .id (1-15).  Then by using a list of block ids, they can experiment with changing the block. Once they have mastered this, they attempt to create a large cuboid of blocks by modifying the code further. As well as working out the parameters of the shape, they have to pay attention to the language as they are now instructing to setBlocks and not setBlock. I find it very useful to get children to check each other’s code and debug errors together. My class are used to my response to their statement of “it doesn't work” (regardless of what type of programming they are doing), of “it is doing exactly what you have told it to do.

Repetition

Introducing repeats can be a big jump, but by using a forever loop, something most primary-aged children will be comfortable with from Scratch, we can then discuss with them the need for programs to keep running if  the instructions are to be applied constantly during the game. The example below returns the player's current position (using x, y, z, coordinates) and then uses that position to change the block below the player's feet. By placing this code within a forever loop, this will happen continuously allowing children to create trails behind their character. Children can tinker with the code to change the position of the block relative to the character, use the setBlocks command to create columns behind them, change the delay before the loop repeats or change the block being placed (TNT.id, 1 - a version of TNT that can be activated by a sword - is a favourite of my class).

Selection

The concept of selection can be introduced by creating an event that will happen if the player stands on a certain block. In the example below, the program checks which block is beneath Steve's feet and, if that block is sand, then turn it into a diamond block. Again the children can tinker with the program to change the conditional statement and the subsequent event.

Programming with Minecraft Pi is not about learning how to code with Python, it is an engaging way of starting the transition from graphical programming to text-based programming. It requires children to use pre-determined vocabulary and syntax and to identify and correct errors in their code. However the use of the minecraft is a huge motivating factor and one that makes them want to check the accuracy of their work, test and explore their ideas and collaborate with others, skills that can be utilised in all areas for the curriculum.

Have you used such tactics to teach programming? Share your experiences below!

Read More

Sign up to our newsletter

Get the best of Innovate My School, straight to your inbox.

What are you interested in?

By signing up you agree to our Terms & Conditions and Privacy Policy.

1,300+ guest writers.
2,500+
ideas & stories. 
Share yours.

In order to make our website better for you, we use cookies!

Some firefox users may experience missing content, to fix this, click the shield in the top left and "disable tracking protection"