QBASIC And Me
When I was 11, there was a computer in our school library that pupils could book in 15 minute time slots on at lunch time. My friends and I were just starting to sit up and pay serious attention to PCs, and we would often stop by during morning break and try to book multiple sesions between us. In later years we sweet-talked our science teacher into letting us use her class computer during lunch breaks, but that’s another story.
At the time, I was excited enough just to be using a PC. There was no internet connection, and the computer refused to run Warcraft II, but for a time I was quite happy to just noodle around in Windows and DOS. Probably the most exciting activity we could legitimately engage in was to browse Encarta for interesting multimedia clips – I was going to make a joke about this, but to this day I like to idle away time on Wikipedia when I’m bored.
Anyway, events took a dramatic turn one day when a friend came into school with wide eyes and a floppy disk, telling wild stories about a exciting program he had stumbled upon. That program was QBASIC, an IDE created by Microsoft and distributed with later versions of DOS – we all had a copy at home, since we had all installed DOS from the same disks. Later that day, we crowded around the library computer as he revealed the contents of his disk. He had written a simple game about anagrams… a jumble of letters would appear, and the player had to type in the unscrambled word or phrase. There was no randomisation, just a simple model of:
- Display a phrase
- (Wait for player input)
- If the input is correct, move on to the next phrase; if not, then repeat the current phrase
It was a terrible game, but we were all interested by the idea of writing our own programs. Like many British schoolchildren of a certain age, we had a little experience of writing BASIC code on a BBC Micro in maths class, but this was another world. We all went home that afternoon and began teaching ourselves to code from the Help files – copy/pasting code samples, fiddling with their parameters and observing the results, that sort of thing. We were also delighted to find some sample games were included – NIBBLES (which was basically Snake) and GORILLAS (which was basically Artillery). Both games were far too complicated for us to understand the inner workings of, but they shined a light on what could be achieved.
Soon, we had all mastered the same handful of commands:
- CLS (clears the screen)
- PRINT (used to write messages on the screen)
- INPUT (allows the user to type things in)
- IF [...] THEN (allows conditional commands – used to create logic gates)
- GOTO (jumps the program to the specified line number)
- END (ends the program)
We used line numbers to create ‘bookmarks’ for useful blocks of code (although in practice we tended to number every line), and learned that putting $ on the end of a word created a string variable (used to store text in speech marks – eg. name$ = “Buck Handsome”) and putting a % on the end of a word created an integer variable (used for numbers, without speech marks – eg. age% = 47), which could be manipulated using normal maths. And if you followed all of that, you already have all the tools you need to create your own games in BASIC.
A simple program would look something like this:
20 PRINT “What is the capital of Burkina Faso?”
30 INPUT answer$
40 IF answer$ = “Ouagadougou” THEN GOTO 60
50 GOTO 10
QBASIC programs run as a linear sequence of commands. You can read it very simply, like a book – start at the first line, and simply follow the instructions, line by line. If you ran this program, it would keep asking you to name the capital of Burkina Faso until you gave the correct answer, whereupon the program would end.
The important thing, from a ‘game’ perspective, is the logic gate created by lines 40 and 50. If the answer is correct, the program jumps ahead to line 60; if the answer is anything else, the program continues to line 50, which loops back to the start. The IF [...] THEN command is a simple tool for evaluating the player’s input – it facilitates the success/failure dynamic which underpins traditional gameplay, and can be layered up to create intricate logic trees. It is what makes this program a ‘game’, even if it is a rubbish, simple game. If you removed lines 40 and 50, the player could type in any answer and the program would always react in the same way, destroying any notions of interactivity, consequences and agency.
To get back to my story, I had a moment of clarity one day – I think it was Easter bank holiday, 1995 – and realised that I could use the random number function to simulate dice rolls. By tracking enough variables (x position, y position, hit points, maximum hit points, magic points, maximum magic points, attack, defence, etc), I could therefore model a simple role-playing game, inspired by boardgames such as Talisman and Hero Quest. This was a far more ambitious project than anything my friends and I had previously attempted, but since it was a long weekend and I had nothing better to do, I dived right in and came back to school on Tuesday with a bugged, but complete, first version of Land of the Lotus.
The game was still terrible – a single, square room, 3×3 tiles large, containing one immobile enemy who could only attack in response to the player’s attacks. But it had a locked door with a working key, three different player classes, and pleasingly generic gameplay. Its pokey little ASCII graphics didn’t quite suggest a living world, but a comatose world that occasionally twitched its fingers, at least. I was overjoyed!
I showed my friends and some of us got together and tried to build on this success – personally, I don’t think I got round to completing any other games, although I wrote a few little applications to crunch numbers for Warhammer and the like. For one of my friends, QBASIC was the starting point for a career in games programming (although he mostly uses C++ these days), and others – including myself – still use the same basic skills it taught us when writing scripts. The moral of this story is that I think QBASIC is a simple and fun way to learn basic principles of procedural logic. It won’t teach you much of anything about object-orientated programming, but on the other hand you can learn everything you need to know to get a game running in just five minutes.
Later this week At some future point in time, I will upload Land of the Lotus: HD Remix, an updated version of the game I threw together 14 years ago, along with the source code. It’s still not a great game by any stretch of the imagination, but I’ve ironed out the bugs, improved the interface, re-written most of the in-game text and annotated my code. And it’s still better than some of the things you’ll find on XBox Live Marketplace.