I’m building a game with books where players can look things up. Rather than doing a pure-topic approach, I want to first have consultation check for an in-scope object (and falling back to just-topic if none found). I think this will help make it easier to match the name of the object with the usual flexibility of name/parse_name.
For example, with my approach you can “LOOK UP BROTHER AELRED IN BOOK”, “LOOK UP AELRED IN BOOK”, “LOOK UP HERBALIST IN BOOK” and they’ll all find the same object, because those are multiple names for it.
However, it acts very strangely if you try to consult a non-existent thing (see example run below)
Here’s my code:
!% ++puny
Constant INITIAL_LOCATION_VALUE = TestRoom;
Constant OPTIONAL_EXTENDED_VERBSET;
Include “globals.h”;
Include “puny.h”;
[ ConsultScope o any ;
switch (scope_stage) {
1: rfalse;
2: objectloop (o ofclass ATopic) PlaceInScope(o); rfalse;
3: rtrue;
}
];
Extend ‘look’ first
* ‘up’ scope=ConsultScope ‘in’ noun → Consult reverse
* ‘up’ topic ‘in’ held → Consult reverse;
Object TestRoom “TestRoom”
with
description “Test Room”,
has light;
Object → MyBook “My book”
with
name ‘book’,
before [;
Consult:
print “consult_words=”, consult_words,
" noun=“, noun,
" second=”, second, “^”;
];
Class ATopic;
ATopic SomeName
with
name ‘somename’;
Object SomeObject
with name 'someobj';
[ Initialise; ];
Here’s the example running:
] look up foo in book
consult_words=1 noun=9 second=0
You discover nothing of interest in the My book.
^ WORKS GREAT, USES TOPIC
] look up someobj in book
consult_words=1 noun=9 second=0
You discover nothing of interest in the My book.
^ WORKS GREAT, USES TOPIC BECAUSE OBJ NOT IN SCOPE
] look up somename in book
consult_words=0 noun=9 second=11
You discover nothing of interest in the My book.
^ WORKS GREAT, USES IN-SCOPE OBJECT
] look up foo in bar
I only understood you as far as "look up" but then you lost me.
^ WORKS GREAT, THERE IS NOTHING IN SCOPE CALLED BAR
] look up somename in bar
^ THIS IS THE STRANGE CASE --- IT PRINTS NOTHING AND DOESN'T CALL CONSULT ROUTINE
] look up someobj in bar
I only understood you as far as "look up" but then you lost me.
^ WORKS GREAT, THERE IS NO BAR
Everything worked fine until I saw a tester use an invalid name for their book and was trying to consult for a valid in-scope object, and it just prints the blank line and nothing. It doesn’t even run the ConsultSub routine.
Does anyone have any theories of what’s going on? Or suggestions about how to solve this can-consult-on-topic and can-consult-on-object.