Supplying a missing noun when there's only one possibility

Hi there!

I’m having a little trouble supplying a second noun. I don’t know where to find this problem in the documentation so I turn to you fellows. :slight_smile:
I want to ask something in a room which only contains one person that is not the player and automatically ask the second person. This is what I got:Rule for supplying a missing noun while asking: if the number of persons in the location is two: now the noun is the person in the location which is not the player.However, Inform doesn’t recognize the last line. How should this be written?

Thanks for your answers! :slight_smile:

(edited to remove non-working non-answer so that people looking for actual solutions aren’t led astray by my inadequate command of the most basic algorithmic concepts.)

Hm, that doesn’t work, I get the error

 The sentence 'now the noun is the first person in the location which is not the player'   appears to say two things are the same - I am reading 'now the noun' and 'first person in the location which is not the player' as two different things, and therefore it makes no sense to say that one is the other

Would you care to post all the code for the new asking action you have implemented? It might be easier to define two separate actions, one for the one-noun case and one for the two-noun case. The one-noun action gets converted into the two-noun action in its check rules.

I think this may be the same problem as here; you can’t define “a random person in the location which is not the player,” because “is not the player” isn’t a relation. You could probably borrow the solution from there:

[code]Difference relates a thing (called X) to a thing (called Y) when X is not Y. The verb to be different from means the difference relation.

Rule for supplying a missing second noun while asking:
if the number of persons in the location is two:
now the second noun is the noun;
now the noun is a random (person in the location) which is different from the player.[/code]

Another trick is that (at least in a similar test) if you leave out those parentheses, then Inform will treat “which is different from the player” as modifying “location” rather than “person,” and so will randomly select either the person or the other person. Putting in the parentheses should let Inform understand that “which is different from the player” modifies “person in the location.”

If you often have occasion to pick out persons who aren’t the player, you could define a phrase for that:

Definition: A person is NPC when it is not the player.

Then you could write:

Rule for supplying a missing second noun while asking: if the number of NPC persons in the location is one: now the second noun is the noun; now the noun is a random NPC person in the location.

At least I think that should work… I seem to be getting an abject failure compiler error when I try to test this, which shouldn’t happen. I’ll kick it around a little more to see if I need to file a bug report. [UPDATE: Never mind, when I was trying to compile it I ended the “if” line with a semicolon, which is known to produce abject failures in the current Inform build.]

…oh, also, you have a line that ends with a period in the middle of your rule. Inform will treat that as ending the rule and will think the next line is meant to start a new rule. Make it a semicolon.

You may also want your Rule for supplying a missing noun to cover the case where two NPCs are in the location by printing a message saying that the player needs to say who to talk to.

(I’ve never seen “the first thing…” before; Arno, are you sure that works? I can’t get it to compile.)

It’s “first thing held by (container/supporter/room)”. This accesses the (fast) I6 child(obj) function, which covers direct containment but not the part-of relation.

However, you can’t say “first thing held by X which COND”.

Yes obviously, my bad. As always, it’s not a good idea to try and answer from memory.

Thanks for all your answers! :slight_smile: That helps me a lot!

A different approach would be to do some list manipulation; this should be pretty efficient:

Rule for supplying a missing second noun while asking:
	Let potentials be the list of persons in the location;
	Remove the player from potentials;
	If the number of entries in potentials is one:
		Now the second noun is the noun;
		Now the noun is the first entry of potentials;

Hey, cool! That’s also a neat possibility I must say. :slight_smile:

I just tried this and apparently, Inform only accepts an “if” instead of the “when”. I guess “when” only applies to times or actions?

Just now I realized that I actually want [code]Definition: A person is NPC if it is not the player.

Rule for supplying a missing noun while asking:
if the number of NPC persons in the location is one:
now the second noun is the noun;
now the noun is a random NPC person in the location.[/code]
Sorry about the confusion. I want to ask something and I automatically want to ask the one NPC person in the room about this. So I only need the noun as I’m already giving the second noun.
However, this doesn’t work, I only get the error message You can’t see any such thing.
Do I need a new action “asking” with only one noun attached?

For this to work, you’d need to set up some grammar for the action that omits the noun and includes the second noun, which I don’t think can be done, because Inform will interpret the first (and, in this case, only) grammar token that it sees as the noun. I tried ‘understand “ask about [text]” as asking it about (with nouns reversed)’, but I7 wasn’t having any of that. I think that, for an action that takes both a noun and a second, you can supply the second, or both the noun and the second, but not the noun alone.

So, yeah, I’d define a new action applying to one topic that redirects to the asking it about action (with the noun filled in using the logic that you quoted in your post) when possible and prints a “you’ll have to be more specific” message otherwise.

Ok, here’s a try that doesn’t work but I don’t know why:[code]Definition: A person is NPC if it is not the player.

Asking about is an action applying to one thing. Understand “ask about [something]” as asking about.

Instead of asking about something (called the referring topic):
if the number of NPC persons in the location is one:
let the person asked be a random NPC person in the location;
try asking the person asked about the referring topic;
say “You must specify who you want to ask about [the referring topic].”.[/code]

You’ve defined your action to take a thing, which you’re trying to pass to the asking it about action, but it expects a topic.

Room One is south of Room Two.

Alice is a woman in Room One.
Instead of asking Alice about "pie", say "'I like pie.'"
Instead of asking someone about something, say "'Huh?'"

Bob and Chris are men in Room Two.
Instead of asking Bob about "pie", say "'I prefer cake.'"
Instead of asking Chris about "pie", say "'Uh... 3.14159...'"

Definition: A person is NPC if it is not the player.

Asking about is an action applying to one topic. Understand "ask about [text]" as asking about.

Instead of asking about a topic when the number of NPC persons in the location is one:
	let the person asked be a random NPC person in the location;
	say "([The person asked])[command clarification break]";
	try asking the person asked about the topic understood.
	
Instead of asking about a topic, say "You must specify who you want to ask about [the topic understood]."	

Test me with "ask about pie / ask about life / n / ask about pie / ask bob about pie / ask chris about pie".

I have quite a big issue here with that:
If an NPC person is on an enterable supporter in the location, nothing will work anymore.

A chair is in Room One. It is an enterable supporter. Alice is on the chair. I get the message: “You can only do that to something animate.” Could it be that"asking about" already has some rules in the standard rule book?

This is my mistake, sorry. I wrote “in the location” when I should have written “enclosed by the location” or, better yet,

when the number of visible NPC persons is one

Something doesn’t count as “in” a room when it’s on a supporter or in a container. “Enclosed by” will capture everything that’s in the room even indirectly. If you could have an NPC that the player can’t see but who’s enclosed by a room (in a closed box, for instance), then switch to “visible,” which will only check the people the player can see.

Well… this still doesn’t work as desired - I only get “You must specify who you want to ask about pie.” when asking in the first room in your example.
This is my code:

[code]Asking about is an action applying to one topic. Understand “ask about [text]” as asking about.

Instead of asking about a topic when the number of visible NPC persons is one:
let the person asked be a random visible NPC person;
say “([The person asked])[command clarification break]”;
try asking the person asked about the topic understood.

Instead of asking about a topic, say “You must specify who you want to ask about [the topic understood].”[/code]

Room One is south of Room Two.

The chair is an enterable supporter in Room One.

Alice is a woman on the chair.
Instead of asking Alice about "pie", say "'I like pie.'"
Instead of asking someone about something, say "'Huh?'"

Bob and Chris are men in Room Two.
Instead of asking Bob about "pie", say "'I prefer cake.'"
Instead of asking Chris about "pie", say "'Uh... 3.14159...'"

Definition: A person is NPC if it is not the player.

Asking about is an action applying to one topic. Understand "ask about [text]" as asking about.

Instead of asking about a topic when the number of visible NPC persons is one:
	let the person asked be a random visible NPC person;
	say "([The person asked])[command clarification break]";
	try asking the person asked about the topic understood.
	
Instead of asking about a topic, say "You must specify who you want to ask about [the topic understood]."	

Test me with "ask about pie / ask about life / n / ask about pie / ask bob about pie / ask chris about pie".

Sorry, I seem to have forgotten to save… :wink: