The WordLength()
routine takes as input the “word” number in the player’s command and returns the number of characters in what the player typed that were matched to that “word”. What counts as a “word” may be different from what you expect because certain things in player input (like commas) are treated as their own word. For example, the command >BOB, JUMP has three “words”: 1 = “bob”, 2 = (comma), 3 = “jump”.
A .parse_name()
routine that signals a match is supposed to return the number of “words” that were matched. You are executing print WordLength(w)
but still have return 3
, so 3 is what is returned by the routine.
As Warrigal notes, there is a routine WordAddress()
that should be in your library (but can be found in StdLib 6/11 or on the forum if needed). That routine returns the memory address of the start of the “word” corresponding to the number given as a parameter. You can then use that address as the basis of a (zero-indexed) character array (->
) to look at the nth character. Something along the lines of this should work as you seem to intend:
Object boiteAllu "boite d'allumettes" piece
with description "Une petite boite d'allumettes.",
name 'petite' 'boite',
parse_name
[c w swn;
swn = wn; ! save parser's current word number pointer
if (NextWord() == 'boite' && NextWord() == 'd^') {
c=(WordAddress(wn))->9; ! ->0 is 1st character of word, ->9 is 10th
w=NextWord();
if(w=='allumette' && c == 's') return 3;
}
wn = swn; ! return current word number pointer to saved place
return -1; ! signal that .name property should be tried next
],
has openable,
has container,
has female;
The above code assumes that your library will be splitting “d’allumettes” into “d’ allumetes” before tokenizing, which I believe is done in the French libraries. The object will match “petite”, “boite”, or “boite d’allumettes” but NOT “petite boite d’allumettes” – to allow more flexible parsing, you might want something like:
Object boiteAllu "boite d'allumettes" Start
with description "Une petite boite d'allumettes.",
name 'petite' 'boite' 'd^' 'allumettes', ! 'allumettes' is same as 'allumette'
parse_name
[chr wd score;
while(true) {
chr=(WordAddress(wn))->9; ! ->0 is 1st character of word, ->9 is 10th
wd=NextWord();
if (WordInProperty(wd, self, name)) {
if (wd == 'allumette' && chr ~= 's') return 0;
else score++;
} else return score;
}
],
has openable,
has container,
has female;
For some useful patterns of .parse_name()
routines see zarf’s tips and tricks at Inform: Parse_Name Variations.