
Players do not type what you expect. They type NORTH instead of N, TAKE instead of GET, go east in small letters, and a space too many. A game that answers I DON'T UNDERSTAND. to all of that is a game nobody finishes. This section rebuilds DRIFT's understanding so that many ways of saying a thing mean the same thing.
Two of S18's tools go to work on every command before anything else: FNCAPS$ turns it into capitals, so CAPS LOCK no longer matters, and FNTRIM$ drops any spaces at the front - of the command, and of the noun, so GO EAST works too.
Every word the game knows goes in DATA, with a number for its meaning:
3300 DATA N,1,NORTH,1,E,2,EAST,2,S,3,SOUTH,3,W,4,WEST,4
3310 DATA GO,5,WALK,5,L,6,LOOK,6,GET,7,TAKE,7,DROP,8
N and NORTH are both 1; GET and TAKE are both 7. Words that mean the same are synonyms, and a new one is just another pair in the DATA. PROCSETUP reads the whole table into V$() and VN%(), going until it reads the word END, so the table can grow without anything else changing.
FNVERB(W$) looks a word up and gives its number - or 0 if the game does not know it. PROCPARSE puts the verb's number in VN%.
GO NORTH and WALK NORTH mean the same as NORTH. So when the verb is GO (number 5), the parser looks up the noun instead, and uses that - as long as it is a direction, 1 to 4. GO FISH is not.
With the verb turned into a number, PROCDO no longer compares words - it compares numbers, and every synonym is handled once, in the table. Lines 1910 to 1987 are replaced with number tests. Three numbers are waiting for S26: OPEN (10), READ (11) and USE (12). Until then, they fall through to I DON'T UNDERSTAND.
LOAD "ADV5". Add these lines, replacing 1830 and 1910 to 1987 where they already exist:
1050 DIM V$(30),VN%(30):RESTORE 3300:NV%=0:REPEAT NV%=NV%+1:READ V$(NV%),VN%(NV%):UNTIL V$(NV%)="END"
1815 C$=FNTRIM$(FNCAPS$(C$))
1830 IF S%=0 THEN V$=C$:N$="" ELSE V$=LEFT$(C$,S%-1):N$=FNTRIM$(MID$(C$,S%+1))
1840 VN%=FNVERB(V$)
1850 IF VN%=5 THEN VN%=FNVERB(N$):N$="":IF VN%>4 THEN VN%=0
1910 IF VN%>=1 AND VN%<=4 THEN PROCMOVE(VN%):ENDPROC
1920 IF VN%=6 THEN PROCLOOK:ENDPROC
1930 IF VN%=7 THEN PROCGET(FNOBJ(N$)):ENDPROC
1940 IF VN%=8 THEN PROCDROP(FNOBJ(N$)):ENDPROC
1950 IF VN%=9 THEN PROCINV:ENDPROC
1985 IF VN%=13 THEN PROCHELP:ENDPROC
1987 IF VN%=14 THEN OVER%=3:ENDPROC
2100 DEF FNCAPS$(A$)
2110 LOCAL I%,C%,B$
2120 FOR I%=1 TO LEN(A$)
2130 C%=ASC(MID$(A$,I%,1))
2140 IF C%>=97 AND C%<=122 THEN C%=C%-32
2150 B$=B$+CHR$(C%)
2160 NEXT
2170 =B$
2200 DEF FNTRIM$(A$)
2210 REPEAT
2220 IF LEFT$(A$,1)=" " THEN A$=MID$(A$,2)
2230 UNTIL LEFT$(A$,1)<>" "
2240 =A$
2300 DEF FNVERB(W$)
2310 LOCAL J%,K%
2320 FOR J%=1 TO NV%
2330 IF V$(J%)=W$ THEN K%=VN%(J%)
2340 NEXT
2350 =K%
3300 DATA N,1,NORTH,1,E,2,EAST,2,S,3,SOUTH,3,W,4,WEST,4
3310 DATA GO,5,WALK,5,L,6,LOOK,6,GET,7,TAKE,7,DROP,8
3320 DATA I,9,INV,9,INVENTORY,9,OPEN,10,READ,11,USE,12,PUT,12
3330 DATA HELP,13,QUIT,14,END,0
4300 DEF PROCHELP
4310 PROCWRAP("TRY: N, S, E, W, LOOK, GET, DROP, INVENTORY, OPEN, READ, USE, QUIT.")
4320 ENDPROC
V$ (the verb) and V$() (the table of words) are two different variables: one with brackets is an array, and has nothing to do with the plain name.
Starting from
LOAD "ADV5" from S24. When it works, SAVE "ADV6".
What you should see
Press CAPS LOCK, and play in small letters:
WHAT NOW? take pad
TAKEN.
WHAT NOW? i
YOU ARE CARRYING:
A DATA PAD
WHAT NOW? go east
CORRIDOR
...
WHAT NOW? north
THE BRIDGE DOOR IS SEALED SHUT.
WHAT NOW? help
TRY: N, S, E, W, LOOK, GET, DROP,
INVENTORY, OPEN, READ, USE, QUIT.
WHAT NOW? xyzzy
I DON'T UNDERSTAND.
(Press CAPS LOCK again afterwards, to type BBC BASIC.)

DATA HELP,13,QUIT,14,GRAB,7,END,0. Now try GRAB PAD.GO EAST, WALK WEST, GO FISH and plain GO. Which work, and why not the others?QUIT, type PRINT NV% and PRINT FNVERB("TAKE");FNVERB("FISH"). What do the numbers mean?25.1 Add EXAMINE and X as more words for LOOK.
25.2 Add CARRY as another word for GET - and check PROCHELP still fits two screen lines.
Worked solutions are in Appendix II.
| Symptom | Cause |
|---|---|
| A new word is not understood | It must go before END in the DATA, and be in capitals there. |
No FN at line 2330 | A = inside the loop. Keep the answer in K%. |
Every command is made capitals and trimmed. Words and their meanings are a DATA table, read once; FNVERB looks a word up, and synonyms are just more pairs. GO looks up its noun. PROCDO tests numbers, not words. Save it as ADV6.
S26, Power And Codes - the puzzles.