Code Club Auckland

Making cool stuff with code!

QBasic Adventure

QBasic is a programming language from the 80s. It's not used much any more, but it used to a very popular language for beginners.

There was no internet back then. Some magazines would have the code for programs written out. You had to type all the code into your computer before you could run the program!

It was pretty weird.


Installing on Windows

1. Download the windows QBasic zip
http://codeclubakl.github.io/qbasic/qbasic-dosbox-win.zip
2. Extract the whole zip file ('Extract all...')
3. Go into the folder qbasic-dosbox-win
4. Double-click on qb.bat

Windows might say you cannot run the program because it's an unrecognized app.

You can make windows trust the app by right clicking on it, opening 'Properties' and clicking 'Unblock'

Installing on a Mac (Apple OS X)

1. Download the mac QBasic zip
http://codeclubakl.github.io/qbasic/qbasic-dosbox-mac.zip
2. Extract the zip file by double-clicking it
3. Go into the folder qbasic-dosbox-mac
4. Right-click on qb.command and choose 'open'

Your Mac might say you cannot run the program because it's from an unidentified developer.

You can still run it by right-clicking or holding control while you click on it.

Choose 'open' from the menu.

Choose 'open' again.

Installing on Linux

We haven't prepared an easy Linux download yet. You'll have to install DOSBox, download QBasic 4.5, then run DOSBox from the terminal giving it the path to qb.exe. Ask a mentor for help if you want.

Use QBasic online (for a Chromebook or any computer)

Click on this link to use QBasic online:

QBasic 4.5 Online – http://codeclubakl.github.io/qbasic/online

Our online version has a few problems:

However it will let you get started. You could kind-of save your work by taking a screenshot?


The QBasic Editor

If it's working you will see this:

Try it out

Type this into the editor:

CLS
PRINT "Hello!"

Then press F5 (you might need to press Function + F5 on a laptop). QBasic will run the program.

CLS means 'clear the screen.'

PRINT writes letters onto the screen.

You should see a black screen that says Hello! and then Press any key to continue.

Well done! Press a key to go back to the blue editor.

Making an Adventure Game

We will make a story game where the player can go to different places.

We need to:

Step 1: Ask a question

CLS
PRINT "Should we go north or south?"
INPUT mychoice$
PRINT "OK, let's go."

Run this program (F5).

The computer runs the program line-by-line, starting from the top.

At INPUT line it stops and waits until you type in something and press ENTER.

It saves your answer into a variable called mychoice$. We will use this next.

Step 2: React to the user's choice

This is the same code as above, with one line added.

CLS
PRINT "Should we go north or south?"
INPUT mychoice$
PRINT "OK, let's go."
IF mychoice$ = "north" THEN PRINT "You found a secret cave!"

Can you guess what this will do? Try reading the code out loud if it helps.

Press F5 to run the program. Can you find the secret cave?

Step 3: Jumping around

Normally, the computer runs the program line-by-line.

We can use GOTO to jump to a different line instead.

In this example, start: is a label. It doesn't do anything by itself, but you can jump to it. cave: is also a label.

CLS
start:
PRINT "Should we go north or south?"
INPUT mychoice$
IF mychoice$ = "north" THEN GOTO cave
PRINT "We can't go that way. Please try again."
GOTO start

cave:
PRINT "You found a secret cave!"
END

Can you pretend to be a computer, and run this program in your head?

Can you add some code so that typing in 'south' makes you go somewhere else?

Step 4: You are in a dark forest…

Now you know enough to make a game. You could make:

Try making something! Remember you can always ask for help.


Extra Ideas

If you want an extra challenge, experiment with these commands.

COLOR 1
PRINT "what color is this?"
PLAY "c d e f"
coins = 4
PRINT coins
PRINT "coins"
IF coins > 3 THEN PRINT "You can catch the bus."

To increase a number, you do this:

coins = coins + 1

It means: let the NEW number of coins be the OLD number of coins plus one.