Two characters in the same room

I want to prevent redundancy when I have two characters in the same room.

When both Alice and Bob are in the room, the text should say “Alice and Bob are here.” When just Alice is in the room, it should say “Alice is here”. And when just Bob is there, it should say “Bob is here”.

I have a “rule for writing a paragraph about” one character, say, Alice. If just she’s there, say “Alice is here.” But if they’re both there, say “Alice and Bob are here.” Bob’s code, if both Alice and Bob are in the same place, should say nothing in that case – but point out if he’s there on his own.

I’ve tried using the “do nothing” command, but that just results in an extra “You can see…”, the type of thing I’m trying to get rid of in the first place.

1 Like

If you don’t mind having the standard message, then Inform already does the grouping out of the box, if you don’t give them “initial appearances”. It will say “You can see Alice and Bob here.” or, for one person, “You can see Alice here.” (or Bob, of course).

If you do want to have a different wording, such as “Alice and Bob are here” or “Alice is here”, as you wrote, then one solution would be to use the activity “Listing nondescript items of something” (and to not give them initial appearances here, either):

Before listing nondescript items:
	say "[A list of people who are marked for listing] [are] here.";
	repeat with named party running through people:
		now the named party is not marked for listing;

Code adapted from the example “Happy Hour”, cf. 7.16. Social Groups and 18.25. Listing nondescript items of something.

6 Likes

This almost works, but I’ve noticed something. If there is another person in the room with an initial appearance description, entering a room results in the text “Nothing is here.” being added. Looking around still shows the normal text, but how can I get rid of that?

Rule for writing a paragraph about a person when there are two or more people in the location:
    say "[The list of people in the location] are here.".
3 Likes

Hmm, I might be overlooking something, but that doesn’t compile for me in I7 v10.1.2. Problem message: “I don’t understand the ‘when/while’ clause, which should name activities or conditions”.

If I change the preamble:

Rule for writing a paragraph about a person when the number of people in the location is at least 2:
	say "[The list of people in the location] are here.".

… then it compiles but produces:

Lab
You, Alice, Bob and Charlie are here.

So I think we’d need at least a refinement to exclude the player character, something like:

Rule for writing a paragraph about a person when the number of people in the location is at least 2:
	say "[The list of people who are not the player in the location] [are] here.".

… which produces:

Lab
Alice, Bob and Charlie are here.

But having said that, I’m not sure if that’s the desired behaviour, since we’re now suppressing the initial appearance (in my scenario, I’ve given Charlie an initial appearance).

And I’m actually not reproducing this:

For me, this example code:

The Lab is a room.

Alice is a woman in the Lab.

Bob is a man in the Lab.

Charlie is a man in the Lab. "Charlie is here with an initial appearance."

The Corridor is north of the Lab.

Before listing nondescript items:
	say "[A list of people who are marked for listing] [are] here.";
	repeat with named party running through people:
		now the named party is not marked for listing;

… produces this output:

Lab
Charlie is here with an initial appearance.

Alice and Bob are here.

>n

Corridor

>s

Lab
Charlie is here with an initial appearance.

Alice and Bob are here.

That seems to be fine, I think?

Ah, okay, further testing showed that it occurs when the person with the initial appearance is the only one in the room.

So, I think this amendment works:

Before listing nondescript items:
	if the number of people who are marked for listing is greater than 0:
		say "[A list of people who are marked for listing] [are] here.";
		repeat with named party running through people:
			now the named party is not marked for listing;
3 Likes

In the interest of tidying up Inform idioms:

Before listing nondescript items:
	if a person is marked for listing:
		say "[A list of people who are marked for listing] [are] here.[paragraph break]";
		now all people are not marked for listing;

I added the “[paragraph break]” to conform with Inform’s usual style, where paragraphs in a room description have a blank line between them (except after the boldface room name).

4 Likes

Following on from Zarf’s ‘code’ - If you wanted only certain ‘groups’ of people to be listed together you could add them together as a kind (as in the example that lists ‘friends’ without an ‘initial appearance’ separately from other people).

The Lab is a room. "A drab laboratory. A store lies to the east."

The Store is east of the Lab. "A cramped store. The only exit is west."

A friend is a kind of person.
	
Before listing nondescript items:
	if a friend is marked for listing:
		say "[A list of friends who are marked for listing] [are] here.[paragraph break]";
		now all friends are not marked for listing;

After going west from the store:
	Move Billy to the lab;
	Continue the action.
	
Alice is a friend in the lab.
Bob is a friend in the lab.

Tommy is a person in the lab.
Jimmy is a person in the lab. "Jimmy is jumping on the spot."

Billy is a friend in the store. The initial appearance of Billy is "Billy stands in a corner sulking."
1 Like

This worked for me, thank you!

NP. This fascinated me, so I was thinking that perhaps you may want to come up with a way to add a friend ‘attribute’ instead of a class that would mean a person could be added to the ‘friends’ group (or removed) as needed. I came up with this - which seems to work :slight_smile: - Not sure how useful it is for your particular requirements, but I found it an interesting exercise.

The Lab is a room. "A drab laboratory. A store lies to the east."

The Store is east of the Lab. "A cramped store. The only exit is west."

A person can be a friend, neutral or an enemy. A person is usually neutral.

A group of friends is a list of people that varies.

Before listing nondescript items:
	repeat with the pal running through a friend marked for listing in the location:
		add the pal to the group of friends;
		now the pal is not marked for listing;
	if the number of entries in the group of friends is greater than zero:
		say "[group of friends] [are] here.[paragraph break]";
		Now the group of friends is {}.
		.
After going west from the store:
	Move Billy to the lab;
	Now Bob is a friend;
	Continue the action.
	
Alice is a person in the lab. Alice is a friend.
Bob is a person in the lab.

Tommy is a person in the lab. Tommy is a friend.
Jimmy is a person in the lab. "Jimmy is jumping on the spot."

Billy is a person in the store. The initial appearance of Billy is "Billy stands in a corner sulking." Billy is a friend.
1 Like

This code results in the text
[** Programming error: tried to read (something) **]
appearing every time it tries to list my friends. Does anyone know what’s happening here?

This error usually indicates that Inform is trying to access a property that the object in question has not been given.

The code as posted above by @AndyG compiles and runs fine in all recent versions of Inform, so I’m assuming you must have inadvertently changed things in some way.

To understand how, we’d need to see an example of code that’s not working.

Actually, on closer inspection the problem is obvious:

repeat with the pal running through a friend marked for listing in the location:

(because kind of object is not specified) cycles through all objects which are ‘friend’, ‘marked for listing’ and ‘in the location’. But objects which aren’t people can’t be ‘friend’ - that’s a property which we’ve said only people can have. So if we put an object in the location which isn’t a person, the above loop looks to see whether that object is ‘friend’ and Inform bails because it’s trying to read the status of a property which doesn’t exist.

Try this instead:

Before listing nondescript items:
	repeat with the pal running through a friend person who is marked for listing in the location:
		add the pal to the group of friends;
		now the pal is not marked for listing;
	if the number of entries in the group of friends is greater than zero:
		say "[group of friends] [are] here.[paragraph break]";
		Now the group of friends is {}.

The problem doesn’t arise in the posted code because all things defined in that code are people.

2 Likes

Thanks Peter - I should have picked up on that! : I did ‘knock something up’ quite quickly and (as in my Spring thing entry) I am learning the lesson, that although you think you have covered all bases, you can never be too sure! - AG