Using CONSULT with topic only, implying the noun

While I’m here asking questions, I might as well get this one off my chest:

I’m attempting to use CONSULT (consulting it about) and while something like “look up penguins in book” or “consult book about penguins” works, I’m running into a problem.

[code]Understand “research [text] in [something]” as consulting it about (with nouns reversed).

Rule for supplying a missing noun while consulting about:
now the noun is a random visible touchable book.[/code]

RESEARCH is behaving properly, as it’s implemented in the same way as “look up” is in the Standard Rules. My problem is that if I try a command like “look up penguins” or “research penguins”, I can’t get Inform to assume the book (or any object at all, for that matter).

“book” is just something I’ve defined as operating as any reference material that can be consulted.

If I use “look up penguins” then I get That noun did not make sense in this context. which, of course, is because Inform thinks it has to do with EXAMINE. With “research penguins” then I get I don’t understand that sentence.

I think I’ve seen someone do this (zarf, probably) with something like:

Understand "research [text]" as consulting it about (with missing noun).

That’s obviously not correct, but I don’t know what the trick is.

Edit: I believe the missing noun statements only work with commands that don’t require a noun, so do I have to re-define consulting it about to only require a topic and no object, and then have the supply missing noun rule?

Usually if you have a problem like this, it’s a good idea to define a new nounless action and redirect it to the one you want. So you could do something like this (untested):

[code]Vaguely researching is an action applying to one topic. Understand “research [text]” as vaguely researching.

Instead of vaguely researching:
if a book is visible and touchable:
let the tome be a random visible touchable book;
try consulting the tome about the topic understood;
otherwise:
say “You can’t see anything to look that up in.” [/code]

As I remember zarf’s advice, if “Supplying a missing noun” isn’t smoothly doing what you want, give up on it and define a new action without as many nouns, which you can redirect the way you want.

…but the trick to get supplying a missing noun to fire is just to write an understand line that’s one noun short, like this:

Understand "open" as opening. Rule for supplying a missing noun when opening: now the noun is the box.

So maybe if you just try:

Understand "research [text]" as consulting it about.

then supplying a missing noun rules will fire. I’m not sure–I’ve never tried it with actions applying to one noun and one topic. (This is what you have without “(with missing noun)”.)

It won’t fire, but you’re right about defining a new nounless action. Here’s the code I used (slight tweak from yours):

[code]Understand “research [text] in [book]” as consulting it about (with nouns reversed).

Vaguely researching is an action applying to one topic. Understand “research [text]” as vaguely researching.
Understand “look up [text]” as vaguely researching.

Instead of vaguely researching:
if a book (called encyclopedia) is visible and encyclopedia is touchable:
let the tome be a random visible touchable book;
try consulting the tome about the topic understood;
otherwise:
say “[We] can’t see anything available in which to research.”
[/code]

It still doesn’t assume a book when you use “look up in” but that’s a very, very minor problem and a rare typo. “research in” supplies the missing noun appropriately because it specifically references a book thing, of course.

Thanks for the solution!

Glad I could help!

One subtlety: the line about “if a book (called encyclopedia) is visible” will choose the first visible book that is defined in the source code (or something like that). If that book is not touchable, then the if-clause will evaluate as false. So in this case:

[code]A book is a kind of thing.

Lab is a room. The glass box is a transparent closed unopenable container in Lab. The Forbidden Index is a book in the glass box. The Ordinary Tome is a book in the Lab.

Understand “research [text] in [book]” as consulting it about (with nouns reversed).

Vaguely researching is an action applying to one topic. Understand “research [text]” as vaguely researching.
Understand “look up [text]” as vaguely researching.

Instead of vaguely researching:
if a book (called encyclopedia) is visible and encyclopedia is touchable:
let the tome be a random visible touchable book;
try consulting the tome about the topic understood;
otherwise:
say “[We] can’t see anything available in which to research.”

Test me with “research penguins”.[/code]

We get “You can’t see anything available in which to research” even though we should be able to look it up in the Ordinary Tome. So it’d be better to change that into “if there is a visible touchable book:”.

And yeah, now that I’ve actually tried incomplete Understand lines like

Understand "look up [text]" as consulting it about.

Inform doesn’t like it because it’s trying to match [text] to the “visible thing” that the action requires. So unless I’m missing something (not unlikely), we need to go the nounless-action route.

That’s because you need to define these.

Understand "research [text] in" as vaguely researching. Understand "look up [text] in" as vaguely researching.

I’ve actually dealt with this exact problem before. One point I found is that if a player types in “look up (something) in encyclopaedia”, then “look up (something else)”, then “look up (another thing)”, it’s usually best to choose the encyclopaedia for the last two rather than a random book. This is what I use.

[code]Looking up is an action applying to one topic. Understand “Look up [text]”, “Read about [text]” and “Read [text]” as looking up.

Understand “Consult [a tome] on/about [text]” as consulting it about. Understand “Look up [text] in [a tome]” as consulting it about (with nouns reversed). Understand “Read about [text] in [a tome]” as consulting it about (with nouns reversed). Understand “Read [text] in [a tome]” as consulting it about (with nouns reversed).

Before doing anything (this is the set tome rule):
if the noun is a tome, now the selected tome is the noun;
if the second noun is a tome, now the selected tome is the second noun.

Carry out looking up (this is the look up rule):
if the selected tome is touchable begin;
try consulting the selected tome about the topic understood;
otherwise;
say “You need to say what book to look up ‘[the topic understood]’ in.”;
end if.[/code]

This way it’ll always choose the last book referred to if it is touchable and give a message otherwise.

Hope this helps.

[It’s good to be back after a 2 year hiatus!]

Wow, terrific! Above and beyond!

I don’t get how the “Before doing anything” statement works though. I’ve never seen that before. Is that somehow referencing the last noun used before the parser clears a variable/buffer or something?

That’s very handy to know. I wouldn’t have understood it as working that way, but it’s quite clear why that would be, now that you’ve mentioned it.

As an aside, complicated if and/or statements seems to be a weak point of Inform. I haven’t noticed a way to conveniently give them an order-of-operation. I can’t think of a good example, but I’ve bumped into it a few times and had to take the long road home.

Not quite. Before doing anything is pretty much a catch all allowing it to fire on every turn. It runs regardless of what the noun or second noun is, although you can specify them. You could also write it like this.

A before rule (this is the set tome rule): (do stuff).

Take a look at “7.9. All actions and exceptional actions” of The Inform Documentation and the “Zodiac” example for more information on how it works.

Hope this helps.

I guess I phrased my question incorrectly.

How does Inform know what “noun” or “second noun” is when there was no noun/second noun entered at the parser?

Does noun and second noun stay active through an indefinite amount of turns/commands until replaced at the parser level? I had just assumed (erroneously, I think) that nouns are automatically reset after every action.

Noun and second noun are set for every action and reset before each new command.

A “before doing anything” rule runs at the start of every action, after those variables are set.

So “before doing anything” is running every turn, waiting (in this case) for a noun to show up that is a book, storing that into a variable that isn’t cleared on a per-turn basis, and then the check rule is examining that variable?

In other words, there’s no way to reference a previous noun unless it’s specifically stored into a variable on purpose – there’s no built-in “noun cache” and no way to intercept the noun pre-next action before it’s cleared.

I think I see how that works now.

If I’m understanding this correctly, you can actually use parentheses; I’ve had occasion to write lines like this:

otherwise if (tracing from feature is false or partial obstructor is nothing) and there is a feature entry:

That’s correct.

(Noun and second noun are still accessible in the “every turn” rules, which run after each turn. But it’s best not to rely on these, because they’re not necessarily what the player typed, for various reasons.)

Yep, that’s exactly what I was going for. For some reason I thought that was disallowed.

Thanks for clearing up my misconceptions, guys. That really unclouded me on a lot of subtle points. Excellent tricks and advice.