Gamemaker and GCSE

gamemaker environment

Gamemaker environment, with list of assets on the left and a room displayed

One piece of software that I’ve enjoyed playing with is Gamemaker. This is a 2d games engine, reasonably easy to use, that can produce games to be uploaded to the website or given to friends as a stand-alone executable file. Gamemaker Studio is the latest version, and is available in a feature-limited free version, an academic version or full professional version. Note that I’ve changed the skin – I find the new default skin (appearance) of the Gamemaker environment very hard on the eyes, and the monochrome effect makes it harder to identify the different icons (You can’t say the blue or the red circle when every single button is in green or grey!).

Gamemaker is a step between Gamestar Mechanic and Scratch or Greenfoot: it is mostly drag and drop elements with settings, rather than scripting (although there is a scripting option) but with more flexibility than Gamestar Mechanic – the interplay of the objects is completely within the creator’s grasp, and there is the full ability to add your own assets: graphics, sound etc.

While Gamemaker serves well as an introduction to programming concepts, it is not a programming environment; rather it is a tool to introduce logical thinking and game making skills.

Using Gamemaker

The Gamemaker environment consists of a list of assets: sounds, background images, sprites, objects, rooms etc. Note that here a sprite is a graphic file, while an object is something that can be added to the game, whereas in Scratch the costume is the graphic and the sprite is the thing that can be added. Each room is one screen (e.g. level selector, start/finish screen), or one game level.

The man object, showing the Event/action interface

The man object, showing the Event/action interface

The basic syntax of Gamemaker is Event -> Action; When this happens, Do this. The creator chooses an event that may happen, e.g. When colliding with… When keyboard <X> pressed… When No more lives left… and then orders the actions that should take place as a result. In this example, the man is designed to move in a maze. He should respond to key presses by moving in the appropriate direction, and should not move when he hits a wall or when no key is pressed.

The direction can be seen/set by double-clicking on the Move in Direction button.

A game can be built up by creating more and more objects, setting their behaviours appropriately and adding them to the game room.

One way to introduce Gamemaker is with a set type of game with recipe cards for extra objects to add in order to increase complexity. Lower ability children can follow the recipes exactly while more able children can start to experiment with settings, and as they gain experience in different types of games they will naturally mix and match.

I find the easiest way to start students on Gamemaker is to start with a maze game. The first objects needed are an avatar and a block to act as the walls. Once the objects are created correctly it is a simple matter to add to them to a room to  create a maze to explore. Then extra objects can be added easily, such as coins to pick up, a door to move to a next level and a bomb or moving enemy. This works especially well as the first step up from Gamestar Mechanic, as the principles of the game/level design should already be understood. With lower ability students, I have created the basics of the game so that they start with something very similar to Gamestar Mechanic, and once they have created the object to move to a new level they work independently on level design while waiting for support to create further objects.

Strengths of Gamemaker

Where Gamemaker excels over Scratch is its built-in facilities to handle things like lives. As it is purpose-built for games, commands already exist to deal with such common features, and it is as simple as saying Event: No more Lives -> Action: Restart game. The game will then finish automatically and restart.

Games such as platform games need a lot more thought, and many objects will stretch children’s ability to work through logically, although features like the built-in gravity property of objects help considerably. Children with low ability/experience will still have high expectations, and so balancing what they want to be able to do with what they can actually achieve by themselves can be a challenge. On the other hand, some children really take to Gamemaker and quite happily explore options by themselves and there are teaching materials available if you look around (some on my site). There are two very good books, The Gamemaker’s Apprentice and The Gamemaker’s Companion, but these are fairly technical and require a good level of ability in order to access them. They are also written for earlier versions of Gamemaker, so might require some checking/adjustment.

Using Gamemaker for coursework/assessment

I looked into using Gamemaker for GCSE and similar qualifications, and found mixed results: OCR GCSE ICT contains a unit on creative use of ICT, for which the solution can be a multimedia presentation, multimedia web pages or a computer game, so using Gamemaker would be a valid way of fulfilling the unit. Other GCSEs did not appear to have that facility, however. Edexcel offers a single and double award ICT, for which the double award contains a unit comparable with the Creative Use of ICT in OCR; information on the types of tasks covered is limited, but the Examiner’s Report suggests that the expectation for a game-based solution would be a scoring system, rules to play/win, single player or turn taking and the ability to include user-created assets, so that would suggest Gamemaker is indeed a viable option.

Other exam boards appear to focus on business use of ICT or traditional multimedia such as web pages or presentations. Even BTEC ICT overlooks game making as a valid use of multimedia, focusing instead on graphics, animation, video, sound or programming.


More on BBC Basic

Since my previous post about BBC Basic I’ve been prompted into looking into the topic further, and it appears the language might have something going for it after all – it’s very similar to the pseudocode used by OCR, and OCR seems to be supporting it, as they have provided training materials using BBC Basic to illustrate solutions.

One problem the language does seem to have is a lack of materials available, so I decided to have a go at remedying that, and have produced a KS3 workbook, similar to my Python workbook, which provides guidance into the first few steps of programming – input, output, variables, IF statements and loops – using BBC Basic, including simple exercises. My intention is that the booklet provides enough information for the more able students to progress by themselves, while others will benefit from extra guidance from their teacher.

I myself missed out on BBC Basic, as by the time it was introduced in schools I was at the top end and about to leave, but I did start off with Sinclair Basic, which was very similar. I do miss the old days of line numbering, but I have to admit that these days it’s far easier! If there is a generation of teachers out there who need to learn how to teach computing in a hurry and they’re already familiar with – or even just have a passing acquaintance with – BBC Basic, then capitalising on that would seem to be a viable way forward.

I intend to look further still into BBC Basic and pseudocode, as students are expected to understand pseudocode anyway for OCR GCSE Computing, and being able to write programs in pseudocode that translate directly into executable code would be useful, but I do feel that there needs to be some sort of introduction to another language as well. Watch this space for more news on training materials.

I remember reading once (a long time ago, admittedly!) that universities don’t want students who have already learned a programming language because they get confused when learning a second, but on the other hand those who already have experience in two find it far easier to learn a third. I myself have found that it’s the thinking and planning skills that are vital – once you understand exactly what you are trying to do, finding the exact syntax in the language of your choice becomes the easy bit. It’s like learning to drive a car: when you first learn, you’re bothered by every small difference in another car – the side the indicator is on, the biting point of the clutch – but once you gain more experience you’re aware of the differences and can work better with the similarities. In the end it doesn’t matter what sort of car you learn to drive in, as long as your skills and knowledge can be easily transferred to any car.

Computer autopsy!

The GCSE computing class is well under way  and seem to be coping well with Python, but we decided that for the last lesson before half term we wanted to try something a little more practical as a treat.  My older computer was dragged back from the shed, where it was residing without a side panel or hard drive, and I took it into class. I also took in my pi and arduino to show them that computers come in different sizes, but it was the big computer that was the main attraction.  I have quite a small group, and they happily got stuck in dissecting the computer.  Those who didn’t want to get quite so hands-on documented the proceedings with a camera and video camera, or researched components on PC World.

We all marvelled at the weight of the CPU, felt the coolness of the heatsink, wondered at the tangle of cables, took the machine completely to pieces and spread it on the desks, then started the reassembly.  They even managed to get it almost back together!  We did discuss the need for earthing to avoid static, and that the components shouldn’t really be handled as much as we did, but I think by the end of the session all who were there were left with a deeper understanding of what’s inside the box on the desk, and while the boys showed no hesitation in dismantling things I learnt a lot too, and at least would feel a little braver in venturing inside should the need ever arise.


BBC Basic

In my look at different languages for use in GCSE computing, I never even considered BBC Basic*, so it was a surprise to discover that it’s the language used in examples given out by OCR and the language used in a new coursebook.

BBC Basic was one of the original languages used in schools, on the BBC Micro.  Back in those days, as I recall, all users learned a form of BASIC – I myself learned Sinclair Basic, on the ZX81.  At that point, each line of code needed a line number, and it was possible to jump from one line of code to another using a command called GOTO, which could result in code that could be hard to read.

password checker in BBC Basic (from OCR)

password checker in BBC Basic

Now it seems that BBC Basic has been updated into a version for Windows.  There is a free version available for evaluation purposes, which limits the size of programs and prevents you producing a stand-alone version of the code.  A paid-for licence is available to lift these restrictions.

My concern is that I cannot understand why this language would be a language of choice for teaching computing.  It’s described as easy for beginners to learn, and it’s based on a language that may be familiar to those who learned their programming a couple of decades ago, but I can see no inherent benefit in using a language that’s purely for teaching and not used in any professional developments, as far as I’ve been able to find out.

I’ve tried hard to show an interest in this language, really I have.  I don’t know whether I have some deep-seated aversion to Basic, but to me this looks clumsy and hard to read, and there seem to be other languages that are free, used professionally and are far easier to read and understand at a glance than this one.  There seems to be no hook to say that BBC Basic is better because…, just the feeling that BBC Basic was the original teaching language so it should still be used.

password checker in Python

password checker in Python

Am I missing something?  Is there some aspect of BBC Basic that makes it better than Python or Java to use?  Because I’m disappointed that OCR have chosen to release their sample code in this one language rather than provide a selection of examples.  The justification given in the book for using the language is that BBC Basic is very close to pseudocode, but I don’t see that it’s any closer than other languages, and I’m left with a feeling similar to one I felt when I originally learnt Basic – that it’s all very well, but it’s not a proper language that is actually used to create real projects.

Feel free to correct me, but this feels to me like something that is being pushed for nostalgic purposes rather than because it’s a good tool for the job. Or am I just carrying over my old teenage prejudices, with all the frustration of trying to write fast, playable games with a tool that was just too slow to work that way?

PS: Originally BASIC was always given in capitals, as an acronym for Beginners’ All Symbolic Instruction Code, but these days it seems to be adopted as just Basic. 

Python – high score table

code for high score part 1

high score code part 1

I’m returning to the high score table task, seeing what I can do with it.  Here I feel my lack of practice probably helps me to see the issues more clearly than if I was a fluent programmer (well, that’s how I’m comforting myself, anyway!).

A reminder of the problem: it’s based on the third task in the specimen paper from OCR GCSE computing, where the requirement is for a high score table to store names and scores for up to 10 players, and be able to write these to a file and read them back in.  I’ve adapted the task a little, so it may well exceed the stated requirements, but then I’m also coming at the code with a hammer rather than a scalpel, I suspect!

I’ve decided to store the high scores in a list of lists, so it will take the format [[335, “Fred Bloggs”],[387, “George Smith”],[938, “Sarah Jones”]], where the first entry relates to the score and the second to the name of the scorer in each case.

Functions that I need to build are:

get_high_score(hstable) returns the highest score and player name

display_high_scores(hstable) prints out the list of scores and names

add_high_score(hstable, score, name) will add a high score to the table if it qualifies

delete_high_score(hstable, name) removes this person and their score from the table

delete_name(hstable, score) removes this score and the associated person from the table

get_high_score(hstable, name) returns the highest score of that person

get_name(hstable, score) returns the name of the person who scored that score

high score code part 2

high score code part 2

I also need to find a way to sort the list so that the scorers are in order from highest score to lowest score.  A little research came up with the way to sort the list by one of the attributes of the inner lists, and a way to reverse that list, by using hstable.sort(key=lambda x: x[0]) then hstable.reverse() – there was supposed to be a way to combine those two commands but the system refused to co-operate on it.

Working out that the easiest way to add a record to the table in the right place if it qualified was to add it to the list, sort the list and then remove the last item if it was more than 10 items long, things quickly fell into place.

The only thing that I had real trouble with was retrieving a saved file, which stubbornly refused to work.  I could check the file had saved correctly, but it refused to load back in.  The console was a real lifesaver, as I could run the file and then type in lines in the console to check the code on the fly.

One other quirk was that when I removed a name from the list two of the three occurrences would be removed.  I could then run the same command again to remove the third occurrence – no idea why it won’t remove all three the first time until I have time to go through step by step.

Generally, though, I’m happy I have a program that will do most of what it’s supposed to, and could quite easily be adapted to be a class for use in a games program.  At this point I think I need to double check the use of the terms functions and methods!

I found that if I got stuck I could generally find the solution somewhere on the web, as long as I knew roughly what I was trying to do, but I’m not sure students new to programming would find it quite so easy.  This is partly why I’m trying to find all the pitfalls and work them out at this stage, so I can make sure they have the best chance of knowing everything they need.  Still, the ability to use class documentation and help systems is invaluable for anyone intending to do any serious coding.


Specimen programming tasks – Python

a program I built to experiment with writing to and reading from files

code I created to play with file input/output

It’s time I started trying out Python to do various tasks, so I’ve started with the specimen tasks for OCR GCSE Computing, as available from their website.  Unfortunately, I can’t really post anything on here about the actual bank of live tasks, but the specimens could make a good start and are publicly available.

There are three tasks in the specimen booklet: the first is to create a maze game in Scratch, and this I’ve totally ignored as it’s the sort of task I start my year 7s on when I first cover Scratch with them, so not really any kind of challenge at all.

The second task proved rather more interesting to tackle, as it asks for a system to check for a password that passes certain tests.  I found there’s flexibility in the task to extend it, as it is vague enough in places to allow for easier or more detailed specifications; it gives examples of how weak, medium and strong passwords could be interpreted, but does not rule in or out using non alpha-numeric characters. The task itself was straightforward: I used a while loop to keep going through the program until the user requests to stop, another while loop to keep asking until the password is the required length, then step through it character by character to check for instances of upper case, lower case and numeric characters, by using ord(e) to obtain the numerical value of the character first.  I use boolean values to check the occurrence of  each type of character, then assign a value of Strong, Medium or Weak as suggested in the task specification.

The third task is proving the most challenge.  This involves writing to and reading from a text file.  At first glance it seems fairly straightforward to do this in Python – open a file in read, write or append mode.  In write mode you create a new file if it doesn’t already exist and wipe the existing content if it does.  In append mode you add text to the end of the file.  In read mode you read back the text in the file, either as a whole or line by line.

The issue I have is how to interpret the requirements of the assignment, and what tools to use.  My programming is such that I can usually do more or less what I need to, but not necessarily in the most efficient way.  For this task I have a choice of techniques, it seems: I can either write plain text to the file, read it back in and then fiddle with it to get it in a format I can use, or I can use a module called pickle which is designed to save objects.  This is more efficient than the previous way but uses its own structure rather than purely reading to and writing from a plain text file.

Another issue is that the specification says that the program needs to locate data in the file by name and highest score, delete an item and associated data from the file and locate and update a high score.  This seems to suggest that the processing should be integrated with the reading and writing of the file, rather than reading in data, processing it and then resaving it in bulk.  Of course I’m not even yet aware of whether Python allows you to amend the contents of the file rather than simply reading or writing.  I’ve a strange feeling it doesn’t.

One source of help on this is the web of course, and I’m still in the process of exploring these resources – I’ve found several forums talking of exactly the same sort of task as this, and wonder if I can find similar threads around for the actual live assignments – that’s something that bodes watching carefully, and any suspicion of plagiarism would need to be counteracted by making sure students understand and can explain the code – after all, there’s nothing wrong with research solutions as a way to learn, but what mustn’t happen is just copying solutions wholesale without understanding.

From what I’ve seen of the model assignments for this qualification, it appears to be generally the tasks that involve reading to and writing from files that provoke the most questions of interpretation, and now I understand why!  At least I’ve learnt a lot from playing with my own code today and have a deeper understanding of the issues needed for answering the assignment tasks.

Python and Scratch – GCSE syllabus part 1

My intention in this post is to take a look at both Python and Scratch, checking them against the OCR GCSE Computing syllabus.  This should then act as a reference when introducing the topics in Scratch and then moving each into the realm of Python.

Programming constructs: sequence, conditionals and iteration plus algorithm understanding: IF and CASE statements, FOR, WHILE and REPEAT loops

control loop blocks in Scratch - repeat x times, repeat until, forever etc

control loop blocks in Scratch

In Scratch: most of these blocks are clear to use.  I’ve included the STOP SCRIPT block in here as it seems to be the equivalent of the BREAK statement, stopping execution of the code block.

Each of these blocks is C shaped, making it straightforward to see what code needs to be executed within the loop.  The student still needs to keep a careful eye on them, however – a series of IF statements can cause confusion, as there is a tendency not to notice whether they are nested or stacked.

The IF/ELSE block provides another useful structure, but this needs to be used carefully as again confusion can be caused if nesting multiple IFs.

code for control loops in python

Python control loops

In Python each piece of code needs to be typed, and the block is defined by very careful use of indenting.

The IF/ELIF/ELSE in Python provides a neater way to produce a series of IF statements, and serves in place of the SWITCH CASE statements of other languages and in the pseudocode used for algorithm description, where the CASE statement is a list of options, and the instructions for each option, although in CASE the choice is usually made on a variable value rather than a logical test , if I remember correctly (SWITCH variable CASE “y” do this, CASE “z” do that, CASE “n” do something else).  In Scratch, this would have to be done with a series of IF/ELSE IF/ELSE statements and tests, where as usual they would have to be placed very carefully.

The important thing to notice in Python layout is that there are no brackets around the logical tests and no formal line ending such as the semicolon in Java, but the start of the block is shown by a colon :

The editor should then indent the start of the next line automatically.  Each line that is indented forms part of the loop, and the non-indented code (or code back to the next level of indenting) will not be executed until the loop is completed.  You do usually need to delete the whitespace yourself to end the code block (one exception to this is the block to define a function – a RETURN line will automatically end the block and reduce the indentation).

While it is not essential to use whitespace this way in other languages, following this sort of layout carefully does lead to far more understandable code, and so it is a very good habit to get into for whichever language you intend to move onto.  Many editors provide support in laying out code neatly, and it may be possible, depending on the editor, to collapse sections of code for easier viewing.

The colour coding of the editor helps in forming good code as well: the secret to maintaining the colour coding after saving the file with the IDLE is to save it with the extension .py – thanks to the reader who reminded me of that one.  While the IDLE will save and recognise the file as Python, it doesn’t actually save it automatically with the right extension!

Notepad++ is another editor which will quite happily save and colour code Python files, incidentally, and will also cope with other languages, such as Java and HTML – again, the careful use of whitespace in these languages leads to better understanding of the code.

python for loop examples

Python FOR loop examples

FOR loops become very interesting in Python, because they provide the opportunity to do more than cycle through a series of numbers.  You specify a range to step through, and the loop will run for each step within the range, but the range may be a number as in a standard for loop (Scratch’s equivalent would be the repeat loop) or it may be items in a list, for example.

In this example code, the results produce the numbers 0-9 (range starts from 0 if not specified, and stops at the value before the end of the range), the numbers 1-9 and then the individual letters in the string “Hello World”.

In Scratch, the equivalent block would be REPEAT XXX, where XXX is the number of times you want the loop carried out.

Python also proves more powerful than Scratch as well because the value of the number of the loop can be used in the body of the program instead of creating another variable, as in these examples where I print out the number of the current step.

The WHILE loop in Python is the equivalent of the REPEAT UNTIL block in Scratch, although the WHILE loop will continue as long as the test is true, while the REPEAT UNTIL will continue until the test is false.  The FOREVER IF loop in Scratch I am not so sure about, as it appears a little confusing – it is really a FOREVER loop with an IF statement inside it, rather than a WHILE block which will finish as soon as the test condition is false.

Scratch logic blocks - greater than less than, AND, OR, NOT etc

Scratch logic blocks

So that’s a look at the basic looping and decision making structures in Python and Scratch.  As to the contents of the conditionals, these both follow the standard content:

In Python equal to becomes == the double equals sign, as a single equals = is used for assignment – when I forgot this, the editor seemed to pick it up and flag it as an error, which is useful.

Also in Python, True and False both start with a capital letter and NOT becomes !, as in x!=4 (x is not equal to 4).  In both languages, conditional statements can be nested as necessary.

Still to look at: data types, input/output, file handling systems, basic string manipulation, one dimensional arrays.variables, operators and assignments.