A sleepy dragon is an unusual meeting. A sleepy dragon asking for a biscuit in a moon cave gives us something more to picture. We’ll turn our sentence builder into a small story, then make the result pleasant to read.
Continue with the final program from Ask, then use the answer.
Keep that program in memory: we are adding to it. If you are joining here, or
using the Spectrum in this page, press Run it here at the end of the lesson,
then Start, and enter the complete first listing below. Alt+P (Option+P on a
Mac) gives each quotation mark and Alt+O each semicolon. After a line number, I
enters INPUT and P enters PRINT. R at an empty input line enters RUN.
Give the meeting a place
Add lines 45, 48 and 60. Keep the other lines:
10 INPUT "Your name ";n$
15 PRINT "Hello, ";n$
20 PRINT "from the Spectrum"
30 INPUT "Describing word ";a$
40 INPUT "Animal ";b$
45 INPUT "Place like moon cave ";p$
48 PRINT "In the ";p$
50 PRINT n$;" met the ";a$;" ";b$
60 PRINT "The ";b$;" asked for a biscuit"Line 45 asks for a place and stores it in p$, another string variable.
Although we type this line after the existing program, its number puts it
between lines 40 and 50. Line 48 introduces the place before the meeting;
line 60 adds the animal’s request afterwards.
Run it with Sam, sleepy, dragon and moon cave. At each prompt, type
between the quotes already supplied and press Enter. For the place, enter
moon cave, not the moon cave: the program supplies In the .
The last line uses b$ again. Reading a stored value does not use it up.
The same animal can appear in both events without asking for its name twice.
Try Jo, enormous, owl and old tower. The words change, but the events
remain a meeting followed by a request. We wrote that structure; the computer
is filling it with answers. The surprise comes from how those choices fit together.
The final sentence may break in the middle of a word at the screen edge. Our next change will give it more room.
Make room for the story
We no longer need the greeting above the finished story. Delete lines 15 and
20: type 15 on its own and press Enter, then do the same with 20.
A line number with no instruction removes that stored line.
Now replace lines 48, 50 and 60, and add lines 5, 46, 47, 55, 65, 70, 75 and 80. Here is the complete program to check against:
5 PRINT "Use short answers"
10 INPUT "Your name ";n$
30 INPUT "Describing word ";a$
40 INPUT "Animal ";b$
45 INPUT "Place like moon cave ";p$
46 CLS
47 PRINT "AN UNEXPECTED PICNIC"
48 PRINT
50 PRINT "In the ";p$
55 PRINT n$;" met the ";a$;" ";b$
60 PRINT
65 PRINT "The ";b$
70 PRINT "asked for a biscuit"
75 PRINT
80 PRINT "THE END"For line 46, type 46, press V to enter CLS, then press Enter. CLS means
clear screen. For an empty PRINT line, type its number, press P, then
Enter without adding quotes or text.
There are three changes to notice:
- Line 5 gives a short instruction while the questions are being answered.
- Line 46 clears the display after the last answer. Printing then starts at the top again, with our title. Clearing the display leaves the program and its stored answers intact.
PRINTwith nothing after it leaves a blank line. Lines 65 and 70 split the last sentence deliberately, keeping the animal and its request readable.
Run it with the first set of answers again.

The questions appear in the Spectrum’s input area near the bottom. Our PRINT
lines use the area above it. When the program finishes, the 0 OK report belongs
to BASIC, not to the story.
If CLS erased the answers as well as the display, could line 50 print the place?
No. Line 50 needs the value in p$. The place appears because CLS clears
what we see, while the stored answer remains available. The screen and the
program’s variables have different jobs.
Make it yours
Change the quoted title in line 47 and the request in line 70. Perhaps the animal asks for directions, or offers a dance lesson. Keep the words short enough to read comfortably. Run the program after each change and see whether the title still suits what happens.
Our design works best with short answers. Try a long animal name and watch
where it wraps; the line break is a display effect, not a shortened value.
Empty answers still leave gaps. Use short answers is guidance for the person,
not a rule enforced by the program.
Ask someone to run it without coaching them. Can they tell what sort of place to enter? Does the result make sense? If a prompt causes confusion, change that prompt and try again. A finished toy can be small; its instructions still need to work for someone who did not write it.
Keep a copy someone can run
Save the program with SAVE "story": press S at an empty input line for
SAVE, then type the quoted name. At the tape prompt, press Enter and wait
for 0 OK.
In the page, keep the tape with the editor below, as in the
saving lesson.
It holds the finished listing. Change the title in line 47 and the request in
line 70 to match yours, then press Download tape to save story.tap. To check
it, press Choose program or disk in the Spectrum panel and select
story.tap. The player loads the tape and the story begins.
Opens in your Spectrum.
Edit this listing, then run it. Changes are marked against the original code.
Working locally, choose Tape → Export Recording… (Ctrl+Shift+E on Linux) and
save to a new filename, such as story.tap. The export contains all recordings in this emulator session. If you saved the
greeting earlier, keep that in mind when loading: use LOAD "story" to ask
for the named program rather than accepting the first one with LOAD "".
The name inside the quotes is the name used by SAVE, not the host filename.
After the export confirmation, close Emu198x and restart it. Choose File →
Open Tape Deck… and select your exported file. Press J for LOAD, type
"story", then press Enter. Choose Tape → Play and wait for loading to
finish. On Linux, launch with --tape "path/to/story.tap", enter the same
LOAD "story" command, then press F9. Keep the --rom option if needed.
The saving lesson
explains these steps in more detail.
Run the recovered program and supply different words. Check that your new title and ending are there. The TAP is the program someone else can run; a screenshot keeps one result they can read.
Decide when this version is finished
Before adding another feature, write down what someone should be able to do with this version. Our small completion check is:
- Load the named
storyprogram from your tape file in a fresh 48K Spectrum. - Read the prompts, enter short answers and see those answers in the finished story.
- See the intended title and ending, then use RUN to make another story with new answers.
Check these after loading the tape file, not just while the program is still
in the session where we wrote it. Keep the matching readable source beside the tape:
copy the final numbered listing into a plain-text file, such as story-v1.bas,
and include our changed title and ending. Compare it with the program we saved.
The text file is a readable record; we still load the TAP to run this version.
If either changes, give the new pair a distinct version name so we can identify which
source produced which program.
Write a short note for the person who will run it:
| What they need | What to record |
|---|---|
| Target | 48K ZX Spectrum BASIC; name the emulator and version we actually checked |
| Files and start | The tape filename, LOAD "story", then RUN after loading |
| Controls | Type a short answer and press Enter at each question; RUN begins again |
| Limits | Long answers may wrap; empty answers leave gaps |
| This version | The title/ending we chose and the matching source filename |
| Evidence | What we loaded and tried; say “not tested on original hardware” if that is true |
Keep a small later ideas list separately: perhaps better handling of long answers, more endings or a different story. Those can be worthwhile without being required for this version. An unreadable prompt or a tape that will not load fails our current check; an extra ending does not.
Try following only the note in a fresh session. When someone else tries it, let them use the note before helping, and improve any unclear instruction. We do not need to publish online or build a commercial product to finish something another person can run.
Story Builder now has a complete ending. Run it again whenever you want another combination. Our next project, Lucky Number, begins with Give a useful clue. We’ll make decisions about an answer and help the player choose again.
Sources
Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming,
second edition (Sinclair Research, 1983), chapter 2 (numbered lines and string
input), chapter 15, p. 103 (CLS and the input/report area), and chapter 20
(tape names, saving and loading).
Run it here
This unit's program, built for you.
- Program
- step-02.tap
- Machine
- ZX Spectrum 48K (PAL)