the-infocom-files / zork2

Zork II: The Wizard of Frobozz
8 stars 4 forks source link

DUMMY is used incorrectly, causing the game to print garbage in some cases #24

Open eriktorbjorn opened 5 years ago

eriktorbjorn commented 5 years ago
>OPEN LID
Have your eyes checked.

>OPEN LID
 t   roomavaiz

That message is printed by PLID-FCN:

    <COND (<VERB? OPEN RAISE MOVE>
       <COND (<FSET? ,PRSO ,OPENBIT>
          <TELL <RANDOM-ELEMENT ,DUMMY> CR>)
         (T <TELL "The lid is now open." CR>)>

RANDOM-ELEMENT is defined in zork-substrate:

<ROUTINE RANDOM-ELEMENT (FROB)
         <GET .FROB <RANDOM <GET .FROB 0>>>>

And so is DUMMY

<GLOBAL DUMMY
        <LTABLE 0
                "Look around."
                "Too late for that."
                "Have your eyes checked.">>

It's an LTABLE, meaning that the first element is the length of the table. In addition, the first visible element is a 0, and that's probably what got picked in the above example. This type of tables is meant to be used with PICK-ONE which uses the first element for some kind of bookkeeping. (I think it has to do with avoiding the same element getting picked twice in a row, or something like that.)

Zork I uses PICK-ONE whenever it uses DUMMY. Zork III doesn't use DUMMY at all. Zork II always uses RANDOM-ELEMENT, which is wrong. It does so in OPEN-CLOSE (twice) and the aforementioned PLID-FCN.

eriktorbjorn commented 5 years ago

I think I've looked through all the uses of RANDOM-ELEMENT and PICK-ONE in the Zork games and substrate, and apart from this the only other incorrect usage I could find is already covered by https://github.com/the-infocom-files/zork2/issues/8