top expert

a biting cat website

Let’s make IF #10: the return of D

Last time on Let’s Make IF…

A good day yesterday! Marbles finally reached the end of the prologue. Along the way, I added conditions for printing room names when they are either local or remote. The first scene (my first scene ever!) ended when Marbles used a new “meowing at” action.

I also wondered if I could consolidate all of my room descriptions into one “to say” phrase.

consolidating all of my room description rules into one “to say” phrase.

Most of the code already exists. The main thing in play here is getting the right table name up-front. I have a configuration table for choosing a table describing D’s current fascination. I’ll just add room names (and probably some complex things like the box later). How to pick the right table, though? In the case of fascinations, those relationships are persistent. But we’re talking about a player’s current action/surroundings here. We’ll have to pick this up in flight. If I just needed to deal with examine, I could tell my phrase to look at the “noun.” However, “look” is reflexive and has no noun. How to address that? There are a couple of options here. I’m initially drawn to creating a completely self-contained phrase that will just handle everything in one place. The other option involves not only a phrase but some action processing items. In both cases, I will need a variable (“a room that varies”) that I can use for checking the config table.

Let’s think about this logically. When do room descriptions print?

  • Looking
  • After going somewhere
  • Examining a room (new)
  • Looking in a direction (new)

Where do these different cases occur during action processing? Looking is a cluster of “carry out” rules (you can see this for yourself by checking the Standard Rules). Examining a room is a “carry out” rule, too. Printing a new room description after going somewhere is a “report” rule. Going somewhere is also sticky because the noun is actually a direction, as in “go north.” Looking in a direction is an “instead” rule that fires off a “carry out” rule. I think that this is doable. As long as we can pick the right table “on the fly,” the stage of action processing shouldn’t matter… we’ll see!

“Consideration” is what I will use to look up the appropriate table name in my newly-renamed “table of references.” How to set this? Because looking has no associated noun, that will have to be accounted for. This will occasion my first use of an “object.” Object is a broader category than things. All things are objects, but not all objects are things. Importantly, “nothing” is an object, but it is not a thing. What can we say the noun of looking is? That’s right, nothing. We don’t need to declare an “object that varies” for this solution, but beginners (like me) probably ought to get acquainted with nothing and nowhere.

	if the noun is nothing:
now the consideration is the location;

Next, I need to deal with the cases where a description prints after going somewhere.

	otherwise if the noun is a direction:
now the consideration is the location;

Since this particular scenario is tied to a reporting rule, the location will be the “new” location and not the starting point.

Finally, for everything else:

	otherwise:
now the consideration is the noun;

The rest is familiar territory. Inform will use the consideration to get a table name, then print text corresponding to the current act from that specified table. What we’ve hopefully done is eliminate complexity and possible points of failure created by multiple copied phrases for things and rooms. That’s right; this should work for examining things, too, though I haven’t needed to fully explore that yet.

d is back!

As I mentioned yesterday, I had unfortunately interfered with “d” as a shortcut for “down.” I gave up a little too early, I think. In fact, I can think of two options. The first, using a “mistake,” is a cool trick that I really enjoy.

understand "blargh" as a mistake("You really have no right to say that to me.").

Mistakes are a quick way to give a text response to a command when a fully implemented action makes no sense. Since text substitutions can execute commands, I could do something like this:

understand "d" as a mistake([flim-flam]).

to say flim-flam:
try going down.

The problem with that, clever as it seems, is that Inform 7 is still treating the substitution as text, adding a paragraph break after the “go down” action is complete. I don’t know how to stop that; it seems baked in, and modifiers like [no line break] don’t do anything. I still have another way out, though.

I’ll just manipulate the player’s command. We can do that with an “after reading a command” rule. These rules fire before action processing even begins. In fact, this is a change to alter the player’s command, substituting it with someone else. There isn’t a lot to it:

after reading a command:
if the player's command in lower case is "d":
try going down instead.

Note that use of “is” rather than “includes” means an exact match. “Dinosaur,” for instance, isn’t going to trigger the going down attempt. Also: I’ve found that it’s always good to negate any dangers that arise from case sensitivity. Inform has no trouble manipulating case in this text, so I almost always account for it with rules matching text. Inform 7 can do a lot with regular expressions, and more advanced programmers often use them. I don’t understand them at all! I’ll stick with good old “if something is x” unless an emergency arises.

There isn’t a lot that can go wrong here. I suppose that there is one thing that might arise in a room with multiple non-scenery objects including D. If the player enters an incomplete command (one with a missing noun), and if those objects (including D) have comparable disambiguation scores, and if the player then answers a “does the player mean” question with “D,” Inform 7 will try going down, rather than examining D or whatever. We’ll see how testing goes, but my call is that this is a lot of “if’s” for something that really isn’t important.

Just like that, D is back.

Here is a link to the drive where all source code backups for this project are stored.

This is today’s updated code. For best results, copy/paste into an Inform 7 IDE.

next.

It’s been kind of a busy day here, so I’m going to wrap it up. A short to-do list:

  • New room descriptions for Act One.
  • A new “thing” to interact with in the auditorium.
  • A closer look at the “box,” in more than one sense.