Tutorial: How to write games

Go to page << 1 2 3 4 5 6 7 8 9 10 11 >>

Getting started

First you need a computer. It will need to be:

Next you need the Basic4GL compiler and development environment.
Fortunately this is available for free from the Basic4GL website: www.basic4gl.net.
You will need to download and install it.

My first program!

Okay! Let's assume you've installed Basic4GL and are ready to go. (If you haven't, there's not much that this tutorial can do for you :)

We're going to write our first program. It will be very simple.

First, run Basic4GL as follows:
Click the windows "Start" menu, then "Programs", then "Basic4GL", then "Basic4GL".

You should see the Basic4GL programming window.

This window looks fairly innocent. Infact it looks a bit like the Windows notepad.
It has an area where you can type into, and and a few buttons on the top.

This however is the Basic4GL editor and is all you need to create and test your own programs. You type them into the text area at the bottom, and run them by clicking the "Go" button on the toolbar.

Here's the first program.

print "Hello world!"

Type this in, then click the "Go" button on the toolbar:

Now one of two things will happen!
If it works, the screen will go black and you will see this:

In the top left hand corner.
Yes, it's the infamous Hello World program. Press a key to finish the program and switch back to the regular screen.

If it doesn't work, you will likely see something like this:

This means there is a syntax error in the program.
If this happens to you, do not panic! Syntax errors occur all the time. They are the programming equivalent of a typo. The computer is simply saying it does not understand what you are trying to do, so you just need to fix it up and try again.

The computer has positioned the cursor at the position of the problem, and has displayed a description of the problem on the status bar (the gray bar at the bottom). In the example, it reads "Unknown variable: prit. Must be declared with DIM."
Sometimes these 'error messages' can be helpful in figuring out the cause of the problem.
In this example, it isn't all that useful, so we need to have a close look ourselves and figure out what is wrong.

Here we have written: prit instead of print

All we need to do is correct the problem, then click the Go button again, and we should get the results we need.

Examining the "Hello World" program

Lets have a look at how "Hello World" worked. It's quite a simple program.
It has just one instruction, consisting of the command print and a parameter "Hello world!".

The print command as you might have guessed prints text on the screen.
You may have noticed that Basic4GL changed its colour to red as you typed it. This is Basic4GL's way of telling you that it has recognised the word "print" as one of its commands.

The "Hello world!" part is what's known as a quoted string. This is how we supply text to the program, so we can tell the print command what we want to print to the screen. The double quotes tell Basic4GL that anything between the quotes are to be treated as text data, so it doesn't try to read it as program code. Basic4GL displays quoted strings in green.

If we remove the quotes from the program and try to run it, it won't work! Because now it treats Hello World! as program instructions. There is no command called "Hello", so Basic4GL will stop and complain.

Saving your program

Once you have a working program that you want to keep, you can save it to disk.
It is also a good idea to save your changes as you go, so that your work isn't lost if something unexpected happens.

Basic4GL saves programs the same way as a text editor would.
You can click "Program|Save", press Control+S on your keyboard, or click the save button

Go to page << 1 2 3 4 5 6 7 8 9 10 11 >>