Begin with three resources: 60 people, 360 grain and 100 acres. They describe one settlement. A year number and a count of people lost will let us follow its history later.
Use a stock 48K Spectrum in BASIC. Start a new program and enter this listing. Meet BASIC offers a slower introduction to keyword entry and editing if useful.
10 BORDER 0: PAPER 0: INK 7: CLS
200 LET pop=60: LET grain=360: LET land=100: LET yr=1: LET lost=0
270 GO SUB 2000
280 STOP
2000 CLS
2100 PRINT AT 0,1; INK 6; BRIGHT 1;"YEARFALL";AT 0,20;"YEAR ";yr
2110 PRINT AT 2,1; INK 5;"PEOPLE ";pop;AT 2,17;"LAND ";land
2120 PRINT AT 3,1; INK 5;"GRAIN ";grain
2250 RETURNRUN it. You should see YEAR 1, PEOPLE 60, LAND 100 and GRAIN 360, followed by a STOP report. The report is deliberate: this first checkpoint draws a settlement and leaves it for inspection. It does not yet accept decisions.
Store the settlement separately
Line 200 assigns numbers with LET. pop, grain and land are numeric variables: names for values the program can change. The names carry our meaning; BASIC does not know what a person or an acre is. yr starts at one and lost at zero. A colon separates statements on the same BASIC line.
Line 270 calls the display routine at 2000 with GO SUB. RETURN sends execution back to the statement after that call, where STOP ends this run. Without STOP, execution would eventually fall into the display routine again and reach a RETURN without a matching call.
PRINT AT uses a text row and column, starting at zero. These are character positions, not pixel coordinates. INK chooses a text colour; PAPER and BORDER establish the background, and CLS clears the display. Colour separates headings, but the labels carry the information.
If you change the printed word PEOPLE to FARMERS, does the population change?
Show the explanation
No. That edits a label. The number still comes from pop, which line 200 sets to 60. Changing a picture or label does not change the stored resource.
For an experiment, replace 360 with 300 in line 200 and RUN again. Only the grain amount should change. Restore 360 afterwards so the following arithmetic uses the same starting settlement. Each RUN reaches line 200 and creates a fresh start; we have not made a saved campaign.
Keyboard notes
In keyword mode, L enters LET, P enters PRINT, H enters GO SUB and Y enters RETURN. Symbol Shift+I enters AT. Symbol Shift+A enters STOP. The ROM supplies the spaces displayed around keyword tokens.
Sources
Steven Vickers, edited by Robin Bradbeer, ZX Spectrum BASIC Programming, second edition (Sinclair Research, 1983), chapter 2, chapter 5, chapter 7, chapter 15, chapter 16.
Run it here
This unit's program, built for you.
- Program
- yearfall.tap
- Machine
- ZX Spectrum 48K (PAL)