A Sequence from an Array
A game needs a sequence. Store a list of panels in an array, then walk it with a loop, flashing and bleeping each in turn. The sequence is data now, not code — the machine plays back whatever the array holds.
A memory game needs something to remember: a sequence. You met arrays in Tally as counters; here an array does a different job — it holds an ordered list, panel after panel, that the machine plays back in turn. Store the sequence as data, and one loop performs it.
10 POKE 53281,0
20 PRINT CHR$(147)
30 DIM PR(4),PC(4),PK(4),PF(4),S(20)
40 PR(1)=4:PC(1)=7:PK(1)=2:PF(1)=30
50 PR(2)=4:PC(2)=21:PK(2)=3:PF(2)=40
60 PR(3)=14:PC(3)=7:PK(3)=5:PF(3)=50
70 PR(4)=14:PC(4)=21:PK(4)=7:PF(4)=60
80 POKE 54296,15:POKE 54277,0:POKE 54278,240
90 FOR P=1 TO 4:GOSUB 1000:NEXT P
100 S(1)=1:S(2)=4:S(3)=2
110 FOR I=1 TO 3
120 P=S(I):GOSUB 1100
130 FOR T=1 TO 100:NEXT T
140 NEXT I
150 END
1000 RP=PR(P):CP=PC(P)
1010 FOR Y=0 TO 7:FOR X=0 TO 11
1020 POKE 1024+(RP+Y)*40+CP+X,160
1030 POKE 55296+(RP+Y)*40+CP+X,PK(P)
1040 NEXT X:NEXT Y
1050 RETURN
1100 RP=PR(P):CP=PC(P)
1110 FOR Y=0 TO 7:FOR X=0 TO 11:POKE 55296+(RP+Y)*40+CP+X,1:NEXT X:NEXT Y
1120 POKE 54273,PF(P):POKE 54272,0:POKE 54276,17
1130 FOR T=1 TO 200:NEXT T
1140 POKE 54276,16
1150 FOR Y=0 TO 7:FOR X=0 TO 11:POKE 55296+(RP+Y)*40+CP+X,PK(P):NEXT X:NEXT Y
1160 RETURN
Line 100 stores the sequence: S(1)=1, S(2)=4, S(3)=2 — red, then yellow, then cyan. Then
lines 110–140 play it: a FOR I = 1 TO 3 loop sets P = S(I) and calls the same flash-and-tone
routine from last unit, with a short pause between steps. The array names which panel; the
routine lights it.
The important shift is that the sequence is now data, not code. The playback loop doesn't
know or care what's in the array — it just flashes whatever each slot names. Put a different list
in S() and the machine performs a different tune, with not a line of the playback changed. That
separation — a list of what, a loop that does the how — is exactly what lets the next unit
grow the sequence without rewriting the player.
Try this
- Compose. Change the three values in line 100 to any panels you like —
S(1)=3:S(2)=3:S(3)=1— and watch the machine play your sequence. - Make it longer. Add
S(4)andS(5), change the loop to1 TO 5, and the machine plays a five-step tune. The array holds as many as you give it.
What's next
The machine plays a fixed sequence. In Unit 4 it grows the sequence by one random panel each round — the escalation that turns a performance into a game.