
S14 filled the list of rooms with four assignments, one per line. For four rooms that is fine. For a map with rooms, exits, descriptions and objects it is page after page of ROOM$(3)=. BBC BASIC has a neater way: write the values out as a list, and have the program read them.
80 DATA CRYO BAY,CORRIDOR,ENGINEERING,BRIDGE
is a line of values, separated by commas. It does nothing on its own. READ takes the next value from it:
READ ROOM$(R)
The first READ takes CRYO BAY, the next CORRIDOR, and so on, in order. BBC BASIC keeps its place, across as many DATA lines as there are, in line number order.
DATA can hold numbers as well as words, and one READ can take several things: READ R$,E takes a word and then a number. The DATA has to give them in the same order.
Words in DATA do not need quotes - unless they have a comma in them. A comma in an unquoted item ends it: ENGINEERING, DECK 2 is read as two items, ENGINEERING and DECK 2. Put it in quotes, "ENGINEERING, DECK 2", and it is one.
READ once too often and BBC BASIC stops with Out of DATA, naming the line with the READ.
RESTORE sends the reading back to the first DATA in the program, so the values can be read again. RESTORE 100 starts from the DATA at line 100 instead - useful when a program keeps several lists.
10 DIM ROOM$(4)
20 FOR R=1 TO 4
30 READ ROOM$(R)
40 NEXT R
50 FOR R=1 TO 4
60 PRINT ROOM$(R)
70 NEXT R
80 DATA CRYO BAY,CORRIDOR,ENGINEERING,BRIDGE
Starting from
A fresh boot, or NEW.
What you should see
>RUN
CRYO BAY
CORRIDOR
ENGINEERING
BRIDGE
>
The same four rooms as S14, but the names are in one place, and adding a room means adding a word to line 80. DRIFT's whole map will be DATA.

FOR R=1 TO 5. What does BBC BASIC say, and which line does it name?"ENGINEERING, DECK 2", with the quotes. Then take the quotes off. What is printed each time, and what has happened to the bridge?>, try PRINT ROOM$(-1). What does that tell you about the bottom end of an array?15.1 Put five numbers in a DATA line, read them, and print their total.
15.2 Put each room's name and how many ways out it has in DATA, and print CORRIDOR HAS 3 EXITS and so on for all four. (The corridor has three; the others one each.)
15.3 Read the same DATA item twice, using RESTORE.
Worked solutions are in Appendix II.
| Symptom | Cause |
|---|---|
Out of DATA | More READs than values. Count them. |
| An item is split in two, and everything after it is one place out | It has a comma in it. Put it in quotes. |
No such variable at a READ | A number was wanted and the DATA had a word there - BBC BASIC took the word for the name of a variable. The DATA is not in the same order as the READ. (The other way round there is no error: a number read into a string arrives as its digits.) |
Subscript | An array number below 0 or above its DIM. |
DATA lines hold a program's values; READ takes them one after another, into any kind of variable. Quote an item with a comma in it. RESTORE starts again, RESTORE n from line n.
S16, Chance - numbers nobody can predict.