Skip to content

Name a room

Give the entrance a name, a description and a place on screen.

  • Sinclair ZX Spectrum
  • BASIC

The cave begins with a place you can recognise. Give the entrance a name and a short description, then leave them on screen. Later, returning to this same place will mean something: it is where the treasures must be brought home.

Use Sinclair BASIC on a stock 48K ZX Spectrum. The Meet BASIC opening explains the keyword editor. Begin a new program with this listing. The ROM supplies spaces around keyword tokens; the readable spaces here do not mean pressing Space after every keyword.

caverns.bas
  10 BORDER 0: PAPER 0: INK 7: BRIGHT 1: CLS
  20 LET a$="The entrance"
  30 LET b$="Daylight rims the stone."
  40 GO SUB 1000
  50 STOP
1000 CLS
1010 PRINT AT 0,8; INK 5;"THE CAVERNS"
1030 INK 1: PLOT 16,148: DRAW 223,0
1040 PRINT AT 5,2; INK 5;a$
1050 PRINT AT 7,2; INK 7;b$
1220 RETURN

RUN it. The heading, room name and description should appear above a STOP report. There are no movement keys yet. STOP deliberately leaves the result available to inspect.

Words are part of the world

a$ holds the room name and b$ holds its description. The dollar sign identifies a string: a sequence of characters rather than a number. Quotation marks mark the text to store. In Sinclair BASIC, a simple string variable has a single-letter name followed by $.

The program visits the drawing routine with GO SUB 1000. RETURN goes back to the statement after that call, which is STOP. Without stopping there, execution could continue into the routine again and reach RETURN without a matching call.

Line 10 selects black paper and border, white ink and bright colours, then clears the screen. The drawing routine clears it again so it can later be called whenever the room changes. A colon separates statements on one numbered line.

Put each kind of information in a stable place

PRINT AT uses character rows and columns, starting at zero at the top left. The title is on row 0, the room name on row 5 and its description on row 7. The two numbers name a position; the semicolon joins the text to the PRINT statement.

PLOT and DRAW use pixels instead. PLOT sets a starting point and DRAW moves from it by a horizontal and vertical displacement. DRAW 223,0 draws the quiet blue separator. Pixel y coordinates increase upwards, unlike character rows.

The room name is cyan, the description white. PRINT’s INK item selects a colour for that output. These colours help reading, but the words carry the meaning. The game is silent and waits for you to think.

If you change b$ to a different description, will the program create a different room?

Show the explanation

It will print different words. There is no room network or player position yet. We are making the display ready for those ideas, one visible result at a time.

Try changing the description and RUN again. Keep it within 28 characters so it will also fit the room records we build next.

Keyboard notes

P enters PRINT, L enters LET, H enters GO SUB and Y enters RETURN after a line number or colon. Q enters PLOT and W enters DRAW. Symbol Shift+A enters STOP; Symbol Shift+I enters AT. Use the linked setup instructions for your emulator’s host-key equivalents.

Sources

Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 5, chapter 8, chapter 15, chapter 16, chapter 17.

Run it here

This unit's program, built for you.

Program
caverns.tap
Machine
ZX Spectrum 48K (PAL)

Download caverns.tap