Dealing with reflexive verbs in text

I’ve been working on some code about plugging cords into sockets and so forth. One of the things in the game I’m writing the code for is an extension cord. Which of course can be plugged into itself. Fine. That all works.

What I don’t like about what I’m doing is encapsulated in this report rule:

Report plugging something into something:
	if old plug is not nothing and old socket is not nothing:
		say "[We] [unplug] [the noun] from [the old socket], [unplug] [the old plug] from [the second noun], and [plug] [the noun] into [the second noun].";
	otherwise if old socket is not nothing:
		say "[We] [unplug] [the noun] from [the old socket], and [plug] it into [the second noun].";
	otherwise if the old plug is not nothing:
		say "[We] [unplug] [the old plug] from [the second noun], and [plug] [the noun] into it.";
		say "[We] [plug] [the noun] into [the second noun]."

That’s mostly fine, except for this output:

> plug cord into cord

She unplugs the extension cord from the socket, 
unplugs the lamp from the extension cord, and plugs the 
extension cord into the extension cord.

Specifically the last part – I want it to say “plugs the extension cord into itself”, which I suppose I could do with a whole bunch more if statements above, but it got me to thinking – has anyone done any work in I7 to deal handling reflexive verbs automatically? What would you do here? Looking for thoughts.

Maybe someone knows a way to produce that pronoun (itself) in those circumstances automatically. I searched in the docs in the 14.5 area (§14.5. Adapting text referring to other things) and couldn’t find a suitable trick.

So what I did was create a tweaked version of the second noun, called [the tweaked second noun].

Since we only ever want to print ‘itself’ if we’ve already referred to the first thing (the first noun) by name in the same line, dropping the tweaked version in wherever I would normally have put [the secound noun] seems to work.

Here’s a demo. I haven’t bothered defining the presentation of the verb [plug] but that’s not the crux of the demo. The crux is showing that it prints ‘itself’ for the plugging action when the second noun is the first.

lab is a room.

a cable is in lab.
a cord is in lab.

plugging it into is an action applying to two things.
Understand "plug [something] into [something]" as plugging it into.

To say the tweaked second noun:
	if second noun is noun:
		say "itself";
		say the second noun;

Report plugging something into something:
	say "[We] plug [the noun] into [the tweaked second noun].";

Test me with "plug cable into cable/plug cable into cord/plug cord into cord".


1 Like

Ah! That’s a neat idea. I always forget that noun and second noun are global variables.

Yeah, though I would use a slightly different global variable here!

To say the (item - a thing) or reflexive:
    if the prior named object is the item:
        say themselves;
        say the item.

Or if you want a one-liner:

[if the prior named object is the item][themselves][else][the item][end if]

The “prior named object” is the object whose gender and number properties Inform consults for pronouns like [them]—and, crucially, the reflexive [themselves]. It gets set whenever you print an object with [the apple] or whatever, or when you use [regarding the apple].

1 Like

The general thing to remember is: for any difficult implementation, someone historically has probably written an extension to work it out.

Not that you need to use the extensions, but sometimes reviewing their code can provide solutions and ideas.

1 Like

My brain gets grouchy with if-elses happening in one line. That’s why all my code looks like the Hanging Gardens Of Babylon, at least in terms of vertical-ness.


Yes indeed, but I wanted to write it myself! :slight_smile:

But boy, Plugs and Sockets does a lot.

1 Like