A Talking ChatBot using ScratchX

I had a great time at the Bett show last week, running a workshop on how to use Scratch to code an interactive talking ChatBot.

The ChatBot asks you questions, and then personalises a conversation with you, based on your responses. This is done using variables (to store information about you) and decisions (so that the ChatBot can decide what to say next).


Here’s how to code the beginnings of a ChatBot:

ChatBot code.png

I had a conversation at the workshop, in which someone commented that it’s a shame the ChatBot doesn’t actually speak.

Well with ScratchX, it can! ScratchX is a place to tinker with experimental Scratch extensions that connect with external hardware (such as electronic devices and robotics) and online resources (including web data and web services).

One of these is a text to speech extension, that includes a new ‘speak’ block to speak text that’s given to it. Clicking the ‘Text to Speech’ extension on the ScratchX homepage opens up the Scratch environment with the additional block in the ‘more blocks’ section. The new ‘speak’ block can then be added to the ChatBot’s code, so that it speaks text before  displaying it on the screen.

Here’s how the ChatBot works with the additional ‘speak’ blocks:

There are other extensions available, including ones to track the position of the ISS or to integrate tweets into Scratch projects!



New Scratch Projects

Here’s an overview of what’s new in our Scratch curriculum:

 memory Memory — memorise and repeat a sequence of random colours!
 dodgeball Dodgeball — a platform game, in which you have to dodge the moving balls and reach the end of the level.
 brain game Brain Game — a times table quiz, in which you have to get as many answers correct as you can in 30 seconds.
catch the dots Catch the Dots — a clone of a great game called ‘Gyro’. Match the dots to the correct part of the controller.
 invaders from space Clone Wars — use lightning bolts to save the Earth from space-monsters.
 create your own world Create Your Own World — learn how to create your own open-world adventure game!

If Ask, Then Answer

My Code Club Journal

Last week was the first week with the full complement of code club members, new and returning.  We filled the computer lab again.  I had a Code Club World project that was new to all of them called Chatbot. I picked this Scratch project because it introduces “ask and answer” code blocks and “if statement” code blocks. Also, the project wasn’t your typical video game.

Chatbot is a new project that has just come out of “beta” testing so it used some aspects of Scratch 2.0 that aren’t available to us as our lab has version Scratch 1.4 installed.  For example the characters the project says to choose from are all 2.0 sprites.

Sprites from Scratch 2.0 Sprites from Scratch 2.0

So I wrote a couple of my own versions of the project to demo to the students and let the students pick a sprite of their choice for the project.

Chatbot Star, a Scratch ver 1.4 demo project Chatbot Star, a Scratch…

View original post 255 more words

Binary Banjo Hero

I recently decided to have a go at making a ‘Guitar Hero’ clone in Scratch!

My first task was to make a guitar. Thankfully, there’s a great ‘Card Guitar’ tutorial on the MakeyMakey website:

Obviously my guitar looks nothing like the one in the tutorial — mine looks more like a banjo, and is made out of a used kitchen roll and an old mobile phone box! 🙂


My ‘banjo’ only has 4 buttons, but by encoding each note in binary it’s possible to play 15 different notes with these 4 buttons.


Here’s the finished game, which uses the ‘z’, ‘x’, ‘c’, and ‘v’ keys. There’s also another version of this project which uses the arrow keys (for playing with the MakeyMakey).

If you want to learn more about how the game was made, you can continue reading below!

The game works by adding up the values of the keys pressed to calculate the binary number total. For example, if the ‘z’ and ‘v’ keys are pressed then the note number is 8+1 = 9.

Screen Shot 2015-01-12 at 16.14.41

Here’s the code that calculates the note number:


As middle C in Scratch has a value of 60 (and not 1)…


…the game code just adds 59 to the binary note value to play the correct note:


This means that in the game, note 1 = c, note 2 = c#, note 3 = d, etc.

To play along to a song, the song also needs to be stored. This is done by using two lists, one for the notes to be played, and one for the times that the notes should be played.


In this example, note 1 (c) is played at 5 seconds, note 1 is played again at 5.5 seconds, note 3 (d) is played at 6 seconds, and so on.

The game creates a cloned sprite for each note, which switches to the correct costume, waits until just before it’s due to be played and then glides to the bottom of the screen:


Here’s a video of me (badly) playing ‘happy birthday’:

Making an RPG Game in Scratch

I’ve been reading up on making a Scratch RPG project, as well as playing some of the amazing RPGs that people have managed to create. Making an RPG is hard, so I’ve tried to create a Scratch project that explores the basics of making an RPG game.

The game can be found here (click the flag to play), and has the following rules:

  • Use the arrow keys to control the main character;
  • The main character can’t move through brown walls;
  • Touching a red enemy kills the main character;
  • The character wins if they get to the green rectangle;
  • If the player touches a black door, they move to the next screen;
  • Touching a yellow door moves to the previous screen.

Scratch RPG

There are only 7 scripts in this project, and as most of the game rules are based on touching certain colours of objects, it means that the game can easily be remixed to create more interesting games.


Here are some possible improvements that can be made to the game:

  • Adding more backgrounds to the stage, with black and yellow doors to allow movement between screens, and brown walls to guide the main character;
  • Adding more enemies to particular screens, that move in different ways, and at different speeds;
  • Improving the graphics, and adding sound to the game;
  • Adding items to collect, possibly along with a score;
  • The game could be made 2-player, with both players having to get to a door to open it.

I’d also like to try using cloud variables, to make a world in which players can meet up online, and work together to solve challenges.

Minecraft, Graphics and Game Design

It’s great to see people’s imaginations fired up after they learn a new coding skill, and I often get asked how difficult it would be to make Minecraft / Flappy Bird / Portal, etc. Although the games they want to recreate are often complex, the ideas behind them sometimes aren’t as complicated as they think.

For example, last year I made a very (very) simple 2-dimensional clone of Minecraft in Python (using Pygame):

Minecraft 2D

In this game, the map is stored as a 2-dimensional list of resources, and the graphics for each resource  are stored in a simple dictionary:

#a dictionary linking resources to textures
textures = {
               DIRT : pygame.image.load('dirt.png'), 
               GRASS : pygame.image.load('grass.png'),
               WATER : pygame.image.load('water.png'),
               BRICK : pygame.image.load('brick.png')

This means that the game graphics can easily be modified, just by editing the images:

Moderately improved graphics

New resources can also be added to the game, by adding them to the relevant lists and dictionaries, and a dictionary of ‘crafting rules’ tells the game which resources can be made from others:

#rules to make new objects
craft = {
            BRICK : { WATER : 1, DIRT : 2 }

I’ve put these challenges together into a new (beta) Code Club project, which can be accessed through the Python projects section of the website. If you’re a volunteer, feel free to try this project out with your club and let me know how you get on: projects@codeclub.org.uk (or use the feedback form on the website). I’d also love to see the finished games that your coders create!


I’m Rik, and soon I’ll be working at Code Club as their Head of Education. This means that I’ll be making and playing games looking after their amazing curriculum, and creating lots more resources. I’m incredibly excited to be working with such a dedicated, hard-working bunch, and looking forward to running my own Code Club in Leeds!

My aim is to ensure that young people learn fundamental coding skills, while at the same time undertaking awesome challenges that get them excited to make things for themselves. I also want to make sure that all Code Club-ers are adequately challenged, regardless of ability or background. Furthermore, these challenges will develop problem-solving, design and collaboration skills as much as possible.

An important part of developing the curriculum will be getting feedback from volunteers, finding out what works well and what works not-so-well. That way, clubs will be exciting, engaging places for young people to learn to code. If you’re a volunteer and have any comments on any of the resources that you’ve used then I’d love to hear from you: rik@codeclub.org.uk.