Unknown Word Error

version 1 by Neil Cerutti

  • Home page
  • Complete text



  • Unknown Word Error by Neil Cerutti begins here.

    "Provides Infocom-style parser messages such as 'I don't know the word 'kludge'.'"

    Include (-
    [ FindUnknownWordToken wordnum
    w twn numwds;
    #ifdef TARGET_GLULX;
    numwds = parse-->0;
    #ifnot;
    numwds = parse->1;
    #endif; ! TARGET_GLULX;
    ! Throw out invalid word numbers
    if (wordnum <= 0 || wordnum > numwds) rfalse;
    twn=wn; ! save the value of wn so it can be restored
    wn=wordnum;
    while (1)
    { w=NextWordStopped();
    if (w == -1) { wn=twn; rfalse; }
    if (w == 0 && TryNumber(wn-1) == -1000)
    { wordnum=wn-1;
    wn=twn;
    return wordnum;
    }
    }
    ];
    -)

    Include (-
    [ PrintToken wordnum
    k l m numwds;
    #ifdef TARGET_GLULX;
    numwds = parse-->0;
    #ifnot;
    numwds = parse->1;
    #endif; ! TARGET_GLULX;
    if (wordnum <= 0 || wordnum > numwds) return;
    k=WordAddress(wordnum);
    l=WordLength(wordnum);
    for (m=0: m < l: m++)
    print (char) k->m;
    ];
    -)

    Include (-
    [ DontKnowError
    wordnum;
    wordnum=FindUnknownWordToken(2);
    if (wordnum ~= 0)
    { print "I don't know the word ~";
    PrintToken(wordnum);
    "~.";
    }
    else rfalse;
    ];
    -)

    To say dunno:
        (-
    return DontKnowError();
    -)

    Rule for printing a parser error when the parser error is can't see any such thing (this is the don't know that word rule):
        say dunno instead.

    Unknown Word Error ends here.