Because your computer has limited storage space, a time will come when you run out–inevitably in the midst of your brillant first program. Remain calm. You can get the space you need.
Here are some signs that you are running out of space:
1) The listing starts shortening. Normally, you can put 22 lines of program on the screen. The line you’re entering can use the bottom 2 lines. When memory gets tight, you get fewer than 22 lines of program display and the working space moves to mid-screen.
2) After typing in a line, you press ENTER, yet ENTER seems to have no effect.
3) ENTER may cause a line to disappear altogether.
4) When you’re really low on memory, characters you type simply will not appear on the screen. This is because the computer has no room to both store and display your input. It chooses to store it. So your program line is in the computer, but you cannot see it.
First get rid of those lines that are not crucial to the running of the program. Try deleting some of your REMark statements.
Next, you can shorten strings (which, remember, are within quotes) by making shorter statements. For example, change
30 PRINT "ENTER PLAYER" to
30 PRINT "ENTER PLY"
Also, keystrokes take up one byte as opposed to spelling the command out. For example, “TO” spelled out takes up two bytes. Shift 4 (TO) uses only one.
Constants, numbers with values that are stored within the program, also take up extra space.
If you use a constant, say 0, often, define it as a variable. Instead of using LET A=0, set another variable equal to 0: LET X=0. Then LET A=X. X takes one byte each time you use it. 0 takes six. Though you spend some memory to set X equal to 0, if your program uses 0 many times, you save in the long run.
You can also shorten variable names. But remember when compacting a program you sacrifice readability to a certain degree. For example:
80 LET PLAYER=P
80 LET PLY=P
Get familiar with the hierachy of algebraic functions to gain extra space by using fewer parentheses. For example: (4*3)+2 can be rewritten as 4*3+2. But, (4+2)*3 can’t be rewritten as 4+2*3 because the computer multiplies first giving a different answer.
Eliminate STOP statements at the end; your program stops when it runs out of lines.
If you have a display in your program, gain space by compressing it into the left corner. The same lines displayed on the right side of the screen take more memory.
By writing a program in modules that don’t pass variables between one another, you can also save yourself some space. But remember to include a CLEAR statement at the beginning or end of each module. For example, a user-friendly intro at the start of your program may ask the user’s name and store it in a string variable. If you never use that variable in the rest of the program, insert a CLEAR statement after that intro routine to free the space that string variable used. And finally, FOR-NEXT loops are more efficient in memory than programmed loops despite the fact that they use 18 bytes (1 byte for character/token, 5 bytes for number, 1 btye at end).
FOR X=1 TO 5
NEXT X
uses less space than:
X=1
LET X=X+1
IF X<=5 THEN ....
Try these suggestions when you need those few extra bytes.