top expert

a biting cat website

let’s make IF s2e2: conditions and text

What are Inform 7 games made of?

last time on let’s make IF.

Last week, I launched season 2 of let’s make IF with a discussion of the most fundamental aspects of Inform 7 development: creating rooms and things, then writing their descriptions. I also defined the “player” (Inform 7’s term for the person controlled by real-world players), giving them a name and a description.

These tasks allowed us to create a simple, playable game. As I said last time, all that an Inform project needs in order to run is a single location. You can review the post in its entirety here:

about Inform 7 games.

The typical Inform 7 work is experienced in text. Players input text commands and receive text responses. A project will almost certainly involve printing text based on conditions. For instance, when the player examines a thing, Inform 7 will print its description. The player-facing part of an Inform 7 project is made up of things and actions. They are both characterized by output as printed text. The mechanisms that print these texts are called “rules.”

In this post, the focus is exclusively on things: their printed descriptions and the terms players use for things in their commands.

conditions and printing text.

Last time, even though I made a lab coat that the player could wear, the description of the player did not change. Here’s some code from last time:

lab is a room.
the description of lab is "This large room was once a laboratory used for some sinister purpose."

the lab coat is in lab.
the description of the lab coat is "Bleached and stiff, as if fresh from the cleaners.".
the lab coat is wearable.

Lux is a person.
the player is Lux.
Lux is in lab.

the description of Lux is "A beginning Inform 7 author."

[lux is one of my pet cats]

If the protagonist wears the lab coat, their description remains unchanged. The lab coat is not mentioned in said description. Let’s think about why. Inform 7’s Standard Rules does not include a complex simulator for wearing clothes. Inform 7 does not know which body parts go with which parts of clothing. In fact, by default, Inform 7 doesn’t know anything about body parts! I’ll say this fairly often: Inform 7 doesn’t understand English. Rather, Inform 7 is a framework for creating a text adventure game using mostly recognizable English phrases.

As a reminder: we can make anything clothing-like by giving it the “wearable property.” This is very straightforward!

the lab coat is wearable.

After the lab coat is donned by the player with a “wear lab coat” command, Inform 7 sees the player and the lab coat as having a special relationship (wearing). I can ask Inform 7 to evaluate whether or not such a relationship (a person wearing something) exists with phrases like “if the lab coat is worn by the player.” Rather than having to say “relationship” in code, it is good enough to use simple English phrases.

I can start using the wearing relation right away in my description of the player.

the description of Lux is "A beginning Inform 7 author.[if the player is wearing the lab coat] You are wearing a snazzy new lab coat![end if]".

Within quoted text like our description of Lux, brackets are used to designate things that are meant to be processed rather than printed. In this example, I’m asking Inform to answer a simple yes or no question: is the player wearing the lab coat? If so, Inform will print whatever text follows. Note that there is a space ” ” between the if condition and the “You are wearing…” text. That’s because we only need the space when the condition is met.

“end if” is not required in this passage since nothing follows the conditional text, but I prefer adding it in every case. Inform has a rather extensive dictionary and built in relationships (like wearing) can be expressed multiple ways. All of these would work:

[if the player wears the lab coat]
[if the player is wearing the lab coat]
[if the lab coat is worn by the player]

It doesn’t matter which way you do it, but I recommend being consistent so that you can search your project for a single phrase if it becomes necessary to find all such situations.

As in real life, relationships are a tricky subject. I won’t be creating any custom ones in this series, but it is worth understanding that a core part of Inform 7 is relationships: relating various in-game things. Wearing clothing is hopefully an accessible example of a relationship we often see in parser games.

What if we wanted to go further? Let’s add another condition to our description:

the description of Lux is "A beginning Inform 7 author.[if the player is wearing the lab coat] You are wearing a snazzy new lab coat![otherwise if the player is not wearing the lab coat] Before beginning your workday, you should put on your lab coat.[end if]"

It really is as simple as that. Note my use of the word “otherwise.” This is exactly what it sounds like. I am saying that both situations cannot be true and that the second condition (not wearing the lab coat) is a fallback. I could have just as easily said “[otherwise]” without the condition, since there is no third possibility. Why didn’t I? Personal preference, mostly. It’s a habit. Inform 7 can support some very complex scenarios, and I try to be specific as general practice.

In fact, we could add an error catching condition: what if neither condition were met? That can’t happen here, but for illustration purposes:

the description of Lux is "A beginning Inform 7 author.[if the player is wearing the lab coat] You are wearing a snazzy new lab coat![otherwise if the player is not wearing the lab coat] Before beginning your workday, you should put on your lab coat.[otherwise]Please let Drew know that you discovered a bug in the description text for Lux.[end if]"

In this example, the “otherwise” is a catch-all for any situation that has fallen through the cracks. It isn’t needed here, but the more complicated your code gets, the more helpful such tactics can be.

understanding.

Last time, I noticed that I could not use the command “examine lux” even though I had defined Lux as the player. Why is that? By default, Inform 7 designates the player “me” or “myself.” This is reasonable: it is uncommon to talk about oneself in third person, and few players seem to want to. However, it’s quite easy to specify synonyms for any thing in an Inform 7 game.

understand Lux as "Lux".

Use of this statement will add “Lux” to Inform 7’s vocabulary of nouns that players can use. Not every thing that exists in a project is part of that vocabulary, though the vast majority are. More usefully, we can use this “understand” imperative to create synonyms.

Most well-crafted games will include synonyms for things and, when helpful, commands. Let’s consider what Inform 7 currently understands as the lab coat.

>x lab
(the lab coat)
Bleached and stiff, as if fresh from the cleaners.
 
>x coat
Bleached and stiff, as if fresh from the cleaners.
 
>x lab coat
Bleached and stiff, as if fresh from the cleaners.

Inform 7 will automatically make synonyms based on our initial name for the noun. Hence, “lab”, “coat”, and “lab coat” all work. However, adding our own synonyms is more complex. I can start by adding a quoted word or words, and then designating the Inform 7 thing that it names.

understand "white jacket" as the lab coat.

That alone covers only exact text entered by the player, so these don’t work:

>x white
You can't see any such thing.
 
>x jacket
You can't see any such thing.

If we want Inform to be more flexible, we’ll have to take further steps. The least complex answer is to state every possibility:

understand "white" and "jacket" and "white jacket" as the lab coat.

This works great, but we might want to handle more complex combinations for this:

understand "white / lab / coat / jacket"

These slashes (with spaces) tell Inform that any of these words, in any order, should be interpreted to mean the lab coat. That is probably too expansive for complex cases (is it a problem if the player types “lab white?), but we can explore that further at a later date. For now, it is enough to know that synonyms make a game player friendly, and that they are easy to specify.

Further reading:

next.

A brief introduction to actions.

Categories: , ,

Leave a comment