Skip to content

Take the file home

Remember the file and recognise a safe return.

  • Sinclair ZX Spectrum
  • BASIC

The file needs a journey home. Reaching it will change what the player carries; the entrance will decide whether that is enough to finish.

Continue from Walk the corridors. This is an unguarded retrieval game, giving us room to check the objective before adding danger.

Replace lines 100, 140, 370, 2030.

Add lines 380, 390, 2500, 2510, 2520, 4000, 4020–4070 in steps of ten, 8000, 8010, 8020.

There are no lines to delete. Enter the changed lines below; their numbers replace existing lines or insert new ones.

changes.bas
 100 LET x=3: LET y=16: LET steps=0: LET got=0: LET outcome=0
 140 GO SUB 1000: GO SUB 2500
 370 GO TO 380
 380 IF x=27 AND y=3 AND got=0 THEN LET got=1: GO SUB 2500
 390 IF x=3 AND y=16 AND got=1 THEN LET outcome=2: GO TO 4000
2030 IF r=3 AND c=27 AND got=0 THEN LET z$=CHR$ 146: LET colour=5
2500 PRINT AT 1,1; INK 5;"TAKE THE FILE. RETURN TO EXIT. "
2510 IF got=1 THEN PRINT AT 1,1; INK 4;"FILE TAKEN. GET BACK TO EXIT.  "
2520 RETURN
4000 LET r=y: LET c=x: GO SUB 2000
4020 IF outcome=2 THEN PRINT AT 1,1; INK 4; BRIGHT 1;"FILE RECOVERED. CLEAN GETAWAY! "
4030 PRINT AT 20,1;"R tries again. Q quits.      "
4040 GO SUB 8000
4050 IF k$="r" OR k$="R" THEN GO SUB 8100: GO TO 100
4060 IF k$="q" OR k$="Q" THEN GO TO 9000
4070 GO TO 4040
8000 GO SUB 8100
8010 LET k$=INKEY$: IF k$="" THEN GO TO 8010
8020 RETURN
Complete program at this stage
night-patrol.bas
  10 GO SUB 7000: GO SUB 7100
 100 LET x=3: LET y=16: LET steps=0: LET got=0: LET outcome=0
 140 GO SUB 1000: GO SUB 2500
 200 LET k$=INKEY$
 210 IF k$="q" OR k$="Q" THEN GO TO 9000
 220 IF k$="r" OR k$="R" THEN GO SUB 8100: GO TO 100
 250 LET k$=INKEY$
 260 LET dx=0: LET dy=0
 270 IF k$="i" OR k$="I" THEN LET dy=-1
 280 IF k$="k" OR k$="K" THEN LET dy=1
 290 IF k$="j" OR k$="J" THEN LET dx=-1
 300 IF k$="l" OR k$="L" THEN LET dx=1
 310 LET nx=x+dx: LET ny=y+dy
 320 IF m$(ny,nx)=CHR$ 145 THEN GO TO 370
 330 IF nx=x AND ny=y THEN GO TO 370
 340 LET r=y: LET c=x: LET x=nx: LET y=ny: GO SUB 2000
 350 LET steps=steps+1: LET r=y: LET c=x: GO SUB 2000
 370 GO TO 380
 380 IF x=27 AND y=3 AND got=0 THEN LET got=1: GO SUB 2500
 390 IF x=3 AND y=16 AND got=1 THEN LET outcome=2: GO TO 4000
 470 GO TO 200
1000 BORDER 0: PAPER 0: INK 7: BRIGHT 0: CLS
1010 PRINT AT 0,1; INK 5; BRIGHT 1;"NIGHT PATROL";AT 0,20;"THE ARCHIVE"
1020 FOR r=1 TO 18: PRINT AT r+1,1; INK 1; BRIGHT 1;m$(r): NEXT r
1022 LET r=3: LET c=27: GO SUB 2000
1024 LET r=y: LET c=x: GO SUB 2000
1030 PRINT AT 20,1;"I up  J left  K down  L right"
1040 PRINT AT 21,1;"R retry              Q quit";
1050 RETURN
2000 LET z$=" ": LET colour=7: LET shade=0
2010 IF m$(r,c)=CHR$ 145 THEN LET z$=CHR$ 145: LET colour=1
2030 IF r=3 AND c=27 AND got=0 THEN LET z$=CHR$ 146: LET colour=5
2040 IF r=16 AND c=3 THEN LET z$=CHR$ 147: LET colour=4
2060 IF r=y AND c=x THEN LET z$=CHR$ 144: LET colour=7
2080 PRINT AT r+1,c; PAPER shade; INK colour; BRIGHT 1;z$: RETURN
2500 PRINT AT 1,1; INK 5;"TAKE THE FILE. RETURN TO EXIT. "
2510 IF got=1 THEN PRINT AT 1,1; INK 4;"FILE TAKEN. GET BACK TO EXIT.  "
2520 RETURN
4000 LET r=y: LET c=x: GO SUB 2000
4020 IF outcome=2 THEN PRINT AT 1,1; INK 4; BRIGHT 1;"FILE RECOVERED. CLEAN GETAWAY! "
4030 PRINT AT 20,1;"R tries again. Q quits.      "
4040 GO SUB 8000
4050 IF k$="r" OR k$="R" THEN GO SUB 8100: GO TO 100
4060 IF k$="q" OR k$="Q" THEN GO TO 9000
4070 GO TO 4040
7000 RESTORE 7500: FOR j=0 TO 31: READ a: POKE USR "a"+j,a: NEXT j: RETURN
7100 DIM m$(18,30): RESTORE 7200
7110 FOR r=1 TO 18: READ m$(r): FOR c=1 TO 30
7120 IF m$(r,c)="#" THEN LET m$(r,c)=CHR$ 145
7130 NEXT c: NEXT r: RETURN
7200 DATA "##############################"
7210 DATA "##############################"
7220 DATA "###########  ############# ###"
7230 DATA "#####        #######     # ###"
7240 DATA "#####                      ###"
7250 DATA "#####     ######   #     #####"
7260 DATA "###### #########  ##### ######"
7270 DATA "######   ############   ######"
7280 DATA "######   ############   ######"
7290 DATA "######  ##############  ######"
7300 DATA "####   ################   ####"
7310 DATA "####   ####  ##########   ####"
7320 DATA "#####        #######     #####"
7330 DATA "#####                    #####"
7340 DATA "#####     ######   #     #####"
7350 DATA "##     #########  ############"
7360 DATA "##############################"
7370 DATA "##############################"
7500 DATA 24,24,0,60,90,24,36,66
7510 DATA 255,128,128,255,8,8,8,255
7520 DATA 126,66,90,66,90,66,126,0
7530 DATA 126,66,66,74,66,66,126,0
8000 GO SUB 8100
8010 LET k$=INKEY$: IF k$="" THEN GO TO 8010
8020 RETURN
8100 IF INKEY$<>"" THEN GO TO 8100
8110 RETURN
9000 PAPER 0: INK 7: BRIGHT 0: PRINT AT 21,0;"Finished. RUN to try again.     ";: STOP

RUN. Walk away from the entrance and return without the file: nothing should end. Reach the file at (27,3), read the changed instruction, then return to (3,16). The result should stay on screen until you choose R or Q.

Remember an event

got is a flag: zero means the file is still waiting, one means you carry it. Line 380 checks the player’s coordinates and sets the flag. The drawing routine now shows the file only while got is zero. When you leave its square, restoring that square produces empty floor.

Line 390 needs both the entrance coordinates and got=1. AND means every condition must hold. Merely standing on the entrance cannot win. The message routine at 2500 also reads got, so the instruction follows the same state as the objective.

Leave the movement loop

outcome starts at zero. A successful return sets it to two and jumps to 4000. We reserve one for capture, which comes with the guard. The result routine redraws the player, prints the ending and waits for a menu choice. It does not return to the movement loop, so holding a direction cannot keep walking after the game ends.

The new 8000 routine reuses the release gate from last lesson, then waits for a fresh key at 8010. A direction held while arriving home is not a result choice. R also waits for release before jumping to 100, where position, got, outcome and steps are reset and the archive is redrawn. Unknown keys return to the result’s input routine.

What would happen if retry reset the position but left got equal to one?

Show the explanation

The player would restart at the entrance already carrying the file. The next objective check could immediately win. Resetting an attempt means resetting its facts as well as its picture.

After winning, retry and check that the file is visible again. Retrieve it a second time, then quit from the result. RUN should start another unguarded attempt. These checks exercise two different ways of starting over: the game’s own reset and BASIC’s program start.

Sources

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

Run it here

This unit's program, built for you.

Program
night-patrol.tap
Machine
ZX Spectrum 48K (PAL)

Download night-patrol.tap