I remember that in the 1980s, on my ZX Spectrum computer with basic, plowing through the pages of my first blanket, basic commands and example code, without any real idea how I could program myself. It was like reading a dictionary where I could learn a few words and their meanings with limited information how can I build them in full sentences to write a document. Every programmaker, who has been dubbed in the basics, has probably come into the famous “Hello word” routine, which includes a two-line program that prints this phrase unlimited times on the screen.
Your program code should be written as a step-by-step instruction that understands your choice of programming language while using the command. It means it is important to read your programming manual to know what you want to do to your program. In the example “Hello World” you will first need a command to print “Hello World” on the screen, and then you will need another command again to print it several times without having to write a print statement.
See this example. To simplify things, I am using old school-basics with line numbers – perhaps because I am a retro-freak.
10 Print “Hello World”
20 goto 10
The best structure to write any program code is clear and easy to follow. Some programmers put many commands on one line which can make it difficult to follow your code if you want to iron the bugs. Spreading your code on many lines actually makes the program better and becomes more readable.
Another recommended practice is to separate each part of your program code by using REM statements. REM (small for the trademark) allows you to remind you before each section of the code what each part does. This is especially useful if you want to edit your code at a later date.
10 rim set up variables
20th A = 1: Late B = 2
30 rpm *******
40 ray print variables on screen
50 ram *******
60 print a, b
After the REM command anything is ignored by the computer and you can easily use many REM statements as you want to make large intervals in your code for reading. Other programming languages allow you to use blank lines or indent the first line of routines.
Now I will show you how to prepare the entire program code. Remember that the computer needs to follow the step-by-step instructions, so you have to write each command in the order you want to run.
Set screen resolutions and variables: The first section of your program will set the screen resolution and variables.
Read the information in the arrays: If you have information that you want to keep in the array using the DIM command, then you can use the For / Next Loop and the READ command. It is best to have a data statement for the array to read at the end of your program.
Set up the main screen: This is the segment where you will use the subtitle (GOSUB command) to set the main screen. In a shoot-M-type game you have a routine that pulls the Sprites and Game screens and then returns to the next line of code.
Main Event Loop: Once the program is running and the main program loop runs, using subroutines jumps into different routines and then returns to the next line in the loop.
Program routine: Keeping all programming routines after the main loop is a good structure. You will have different routines that update the screen, check joystick input, check for collision detection and so on. After each checking you return to the main loop.
Data Statements: Finally you can list all the data statements at the end of the program, which makes it easy to find and correct when needed.