Consulting an object problem in PunyInform

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.

1 Like

Oh, and if the ConsultScope routine returns true for #2, it also has the same strange behavior.

When a scope routine is called with scope_stage set to three, you are supposed to print an error message. You have chosen not to do so. Thus, crickets.

2 Likes

Also note that creating an object for every topic isn’t a great fit for PunyInform. Look at the Library of Horror source for an idea on how to reduce object count and space requirements for topics.

1 Like

Ohhhhh! That’s that the third pass is for. Thanks!

And 100% agree of topic-objects-waste-space; they’re not just topics: they’re the real objects from the game with a property added on them (in the example code I just made them ATopic object). This way, if you can look up herbs in the book, I just put a herb_text property on every herb that exists already in the game. I did see how you handled it in LOH; I just thought it would nice to keep the descriptions with the actual objects in this case.

Thanks so much, @fredrik !

2 Likes

Just want to drop a note to say I really like this system you’re making.

Recently, in A Flustered Duck, I realized that the game would allow for disambiguation in conversations; if I asked someone about “man”, it would ask me who I meant, and give me a list of all men in the game. In a format that made me think it was also matching against existing objects.

In your system, does something similar happen? If I look up a term like “herb”, in a world with parsley, sage, rosemary and thyme, will it automatically ask me which I mean and accept the answer as it would any disambiguation? Or is that a bit much? :slight_smile:

The idea of using objects as dialog topics (when appropriate to do so) and letting the system use their already-defined synonims appeals to me.

1 Like

@Giger_Kitty : Eeek! If I do “LOOK UP HERB IN HERBAL”, it does give a list of possible herbs in the book — which, in my case, I don’t want, even though it was the right case for you. I didn’t check that and it has come up in testing, but now I’ll fix that. :slight_smile:

So: helpful for you, but in this case, not for me.

2 Likes

I do have a talent for stepping in and mucking things up. Just like every player ever. :grin:

I’m sure Jim Aikin probably didn’t mean for it to happen in Flustered Duck either, but as a player, I tell you, it’s really really convenient. :innocent:

That doesn’t sound too bad - it’s an index page! :innocent:

I kid, I see why you wouldn’t want that.

2 Likes