Change a description depending on where the character is

In my game, I have a character who follows you around, and I want their description to be different depending on where they are. I tried setting up a table for it (it’s much easier to edit and add to than just a bunch of if statements), but I’m not quite sure what the syntax could be. I read the docs and set up a table with two columns: one for the place and one for the description.

"Location Examining Practice" by Scrooge200

The Planetarium is a room. South of the Planetarium is the Gift Shop. Lady Bracknell is a person in the Planetarium.

Carry out going somewhere:
	now Lady Bracknell is in the location;
	say "Lady Bracknell strides in. [first time]She insists on keeping a watchful eye on you.[only]";

[Rule for writing a paragraph about Bracknell (this is the Bracknell paragraph rule):
	if the location of Bracknell is listed in the Table of Bracknell Idle Actions, say "[description entry][paragraph break]";
	
Table of Bracknell Idle Actions
bracknell-room	description
"Planetarium"	"'This planetarium [italic type]certainly[roman type] does not compare to my personal astronomer's room back at home,' Lady Bracknell tells you."
"Gift Shop"	"Lady Bracknell turns her nose up at some of the cheap knickknacks on display."]
1 Like

This is almost right, you just have a few small issues with the table and another with the going somewhere rule.

Taking the second first, “the location” is going to be where the player started the turn, not where they ended the turn – this is a counterintuitive bit of Inform that often trips people up! Fortunately, the going action has an action variable called the room gone to that will work for your purposes.

As to the table, the easiest way to do this is just to tell Inform to look up the description entry corresponding to Bracknell’s location – and note that you want the Bracknell-room column to be a list of rooms, not a list of texts, which is what the quotation marks will give you.

Putting the pieces together, this should work:

The Planetarium is a room. South of the Planetarium is the Gift Shop. Lady Bracknell is a person in the Planetarium.

Carry out going somewhere:
	now Lady Bracknell is in the room gone to;
	say "Lady Bracknell strides in. [first time]She insists on keeping a watchful eye on you.[only]";

Rule for writing a paragraph about Bracknell (this is the Bracknell paragraph rule):
	Say the description corresponding to a bracknell-room of location in the Table of Bracknell Idle Actions.
	
Table of Bracknell Idle Actions
bracknell-room	description
Planetarium	"'This planetarium [italic type]certainly[roman type] does not compare to my personal astronomer's room back at home,' Lady Bracknell tells you."
Gift Shop	"Lady Bracknell turns her nose up at some of the cheap knickknacks on display."
6 Likes

Thank you, this works well! I also slightly modified the code so that Lady Bracknell’s description will update depending on the room you’re in, and she has different commentary when you go somewhere new.

"A Trip to the Planetarium, Featuring Lady Bracknell" by Scrooge200 and Mike Russo

The Planetarium is a room. South of the Planetarium is the Gift Shop. Lady Bracknell is a person in the Planetarium.

Carry out going somewhere:
	now Lady Bracknell is in the room gone to;
	say "Lady Bracknell strides in. [first time]She insists on keeping a watchful eye on you.[only]";

Carry out examining Bracknell:
	now the description of Lady Bracknell is the description corresponding to a bracknell-room of location in the Table of Bracknell Idle Actions;

Rule for writing a paragraph about Bracknell (this is the Bracknell paragraph rule):
	Say the entry corresponding to a bracknell-room of location in the Table of Bracknell Idle Actions.
	
Table of Bracknell Idle Actions
bracknell-room	entry	description
Planetarium	"[one of]As you step foot into the Planetarium, Lady Bracknell is right behind you. 'Be a proper young lady and don't get distracted by cheap merchandise, okay?'[or]Lady Bracknell sighs with relief, glad that you didn't ask her to buy anything.[stopping]"	"'This planetarium [italic type]certainly[roman type] does not compare to my personal astronomer's room back at home,' Lady Bracknell tells you."
Gift Shop	"Lady Bracknell sighs, displeased by your tendency to be distracted by such gaudy trinkets."	"Lady Bracknell turns her nose up at some of the cheap knickknacks on display."
2 Likes