
Seeing a data pad is one thing; picking it up is what an adventure is about. The player types GET PAD; the program has to find out which object PAD is, check that it can be taken, and move it into the player's hands.
FNOBJ(N$) looks for each object's word inside the noun the player typed, with INSTR. It hands back the object's number, or 0 if none matched. Because it looks for the word inside the noun, GET PAD and GET DATA PAD both find the pad.
It uses S22's lesson: the loop records what it finds in K%, and the function answers only after the loop has finished.
Carrying is only a number: taking the pad sets L%(1) to 0, "with the player". Dropping it sets it to the room you are in. Nothing moves anywhere; the program just writes down where things are.
PROCGET checks, in order: did the player name anything at all? do they already have it? is it here? is it fixed? Each check that fails says why and ends the procedure. Only an object that passes all four is taken.
The first check matters more than it looks. When nothing matched, FNOBJ gives 0 - and there is an L%(0), because arrays start at 0, and it is 0, which means "carried". Without the check, the game would think you were holding an object that does not exist.
LOAD "ADV4". Add:
1500 DEF PROCGET(I%)
1510 IF I%=0 THEN PRINT "YOU CAN'T SEE THAT HERE.":ENDPROC
1520 IF L%(I%)=0 THEN PRINT "YOU ALREADY HAVE IT.":ENDPROC
1530 IF L%(I%)<>R% THEN PRINT "YOU CAN'T SEE THAT HERE.":ENDPROC
1540 IF F%(I%) THEN PRINT "IT WON'T MOVE.":ENDPROC
1550 L%(I%)=0:PRINT "TAKEN."
1560 ENDPROC
1600 DEF PROCDROP(I%)
1610 IF I%=0 THEN PRINT "YOU AREN'T CARRYING THAT.":ENDPROC
1620 IF L%(I%)<>0 THEN PRINT "YOU AREN'T CARRYING THAT.":ENDPROC
1630 L%(I%)=R%:PRINT "DROPPED."
1640 ENDPROC
1700 DEF PROCINV
1710 LOCAL I%,N%
1720 PRINT "YOU ARE CARRYING:"
1730 FOR I%=1 TO 4
1740 IF L%(I%)=0 THEN PRINT " ";OD$(I%):N%=N%+1
1750 NEXT
1760 IF N%=0 THEN PRINT " NOTHING."
1770 ENDPROC
1930 IF V$="GET" THEN PROCGET(FNOBJ(N$)):ENDPROC
1940 IF V$="DROP" THEN PROCDROP(FNOBJ(N$)):ENDPROC
1950 IF V$="INVENTORY" THEN PROCINV:ENDPROC
2400 DEF FNOBJ(W$)
2410 LOCAL J%,K%
2420 FOR J%=1 TO 4
2430 IF W$<>"" AND INSTR(W$,O$(J%)) THEN K%=J%
2440 NEXT
2450 =K%
Starting from
LOAD "ADV4" from S23. When it works, SAVE "ADV5".
What you should see
WHAT NOW? GET PAD
TAKEN.
WHAT NOW? INVENTORY
YOU ARE CARRYING:
A DATA PAD
WHAT NOW? GET PAD
YOU ALREADY HAVE IT.
WHAT NOW? E
CORRIDOR
...
WHAT NOW? DROP PAD
DROPPED.
WHAT NOW? DROP PAD
YOU AREN'T CARRYING THAT.
WHAT NOW? GET LOCKER
IT WON'T MOVE.
WHAT NOW? GET FISH
YOU CAN'T SEE THAT HERE.
WHAT NOW? INVENTORY
YOU ARE CARRYING:
NOTHING.

LOOK. Where is the pad now?TAKE PAD. Then GET DATA PAD. Why does one work and not the other?1545 IF I%=1 AND R%=1 THEN PRINT "IT IS FROZEN TO THE FLOOR.":ENDPROC, and try to take the pad in the cryo bay.24.1 Make GET refuse the power cell with a message of your own. (It is object 2.)
24.2 Why does line 1510 come first? What would the game say to GET FISH without it?
Worked solutions are in Appendix II.
| Symptom | Cause |
|---|---|
TAKE PAD is not understood | Only GET is, for now. S25. |
| An object you dropped has vanished | It is in the room you dropped it in. LOOK there. |
No FN at line 2430 | A = inside the loop in FNOBJ. Record, finish the loop, then answer. |
FNOBJ turns the player's noun into an object number. Taking an object sets its place to 0; dropping sets it to the room. PROCINV lists everything whose place is 0. Save it as ADV5.
S25, Understanding The Player - many ways of saying the same thing.