In an upcoming WIP I very specifically need to be able to give an “I don’t know the word ___” error, separate from “you can’t see any such thing”. There used to be an Unknown Word Error extension for this, but I can’t find any updated version for Inform 10…or, for that matter, the most recently updated version so I can hack it myself.
This is a rebuild of the old version, taking advantage of I6 routines that should be in template code:
Include (-
[ FindUnknownWordNumber wordnum i numwds;
numwds = WordCount();
! Throw out invalid word numbers
if (wordnum <= 0 || wordnum > numwds) rfalse;
for (i = wordnum: i <= numwds: i++) {
if (WordFrom(i, parse) == 0 && TryNumber(i) == -1000) {
return i;
}
}
rfalse;
];
[ PrintWordAt wordnum ;
if (wordnum <= 0 || wordnum > WordCount()) rfalse;
PrintSnippet(wordnum*100+1);
];
-).
To decide what number is the/-- position of the/-- first non-dictionary word:
(- FindUnknownWordNumber(1) -)
To say the/-- word at position/-- (N - a number):
(- PrintWordAt({N}); -)
Rule for printing a parser error when the latest parser error is the can't see any such thing error (this is the don't know that word rule):
Let N be the position of the first non-dictionary word;
if N is zero:
make no decision;
say "I don't know the word '[word at position N]'."
Rule for printing a parser error when the latest parser error is the not a verb I recognise error (this is the don't know that verb rule):
Let N be the position of the first non-dictionary word;
if N is zero:
make no decision;
if the American dialect option is active:
say "I don't recognize the verb '[word at position N]'.";
otherwise:
say "I don't recognise the verb '[word at position N]'."
Note that it still will print “You can't see any such thing.” in cases where a known word doesn’t correspond to anything in scope.
The idea was that it would print the first non-dictionary word starting at the position given as a parameter. However, I didn’t name the routine to reflect that, or change the name of the phrase that uses it, so I see why it’s confusing! Sorry about that – I was stripping down the I6 part from something more involved from my own files to match the original’s scope (and working too quickly, obviously). I’ve updated the code above.
Unknown Word Error by Daniel Stelzer begins here.
"Adds a separate parser error for unknown words."
"based on original code by Neil Cerutti, adapted for version 10 by Otis the Dog"
Volume - All
Include (-
[ FindUnknownWordNumber wordnum i numwds;
numwds = WordCount();
! Throw out invalid word numbers
if (wordnum <= 0 || wordnum > numwds) rfalse;
for (i = wordnum: i <= numwds: i++) {
if (WordFrom(i, parse) == 0 && TryNumber(i) == -1000) {
return i;
}
}
rfalse;
];
[ PrintWordAt wordnum ;
if (wordnum <= 0 || wordnum > WordCount()) rfalse;
PrintSnippet(wordnum*100+1);
];
-).
To decide what number is the/-- position of the/-- non-dictionary word:
(- FindUnknownWordNumber(1) -)
To say the/-- word at position/-- (N - a number):
(- PrintWordAt({N}); -)
The don't know that noun error is a command parser error.
The don't know that verb error is a command parser error.
Before printing a parser error (this is the add non-dictionary errors to the parser rule):
if the latest parser error is the can't see any such thing error and the position of the non-dictionary word is not zero:
now the latest parser error is the don't know that noun error;
otherwise if the latest parser error is the not a verb I recognise error and the position of the non-dictionary word is not zero:
now the latest parser error is the don't know that verb error.
Last rule for printing a parser error when the latest parser error is the don't know that noun error (this is the don't know that noun rule):
let N be the position of the non-dictionary word;
say "I don't know the word '[word at position N]'."
Last rule for printing a parser error when the latest parser error is the don't know that verb error (this is the don't know that verb rule):
let N be the position of the non-dictionary word;
say "I don't know the word '[word at position N]'."
Unknown Word Error ends here.