Welcome to Adventure: Lesson 6 (Scoring, New Properties, New Kinds, and Ending the Game)

Introduction

This is the sixth in a series of quick-start Inform 7 tutorials using examples from Colossal Cave Adventure. More information about this tutorial series can be found here: A Quick-Start Guide to Inform 7.

Scoring

In the early days, many text adventures relied upon a scoring system to encourage players along. By default, Inform 7 games do not have scoring, but this can be changed easily. To turn on Inform’s built-in scoring system:

Use scoring.

(Sometimes, it’s just that easy.)

With scoring turned on, the next step is to specify a maximum score:

The maximum score is 350.

Here’s how to award points to the player:

Some bars of silver are a thing. The bars of silver are in Low N/S Passage.

After taking the bars of silver:
    increase the score by 5;
    continue the action.

The reason for the “continue the action” instruction is that after rules replace report rules. The report rule for taking is what prints “Taken” at the end, so without that “continue the action”, there would be no announcement of the action’s success. (For more about Inform 7’s action rules, see Lesson 5.)

Adding New Properties

There is a small problem with the syntax above – not a programming problem, but a design problem. The score increase triggers every time the player takes the bars of silver.

silver abuse

This kind of abuse can be avoided in a few ways. The best way for this exact example is probably to use the built-in property “handled”.

handled option

Another way to handle this is to add new properties. Here, I’ve added the “scored” property to the bars of silver.

Some bars of silver are a thing. The bars of silver are in Low N/S Passage. The bars of silver can be scored or unscored. The bars of silver are unscored.

After taking the bars of silver:
    if the bars of silver are unscored:
        increase the score by 5;
        now the bars of silver are scored;
    continue the action.

scored option

Using Kinds

It’s all very well to put “scored” and “unscored” on the bars of silver. But there are many treasures in Adventure, and adding a new property and an “after” rule for every single one would be extremely cumbersome and dull.

The items you’ve been creating – the wicker cage, the little bird, the tasty food, the bars of silver – are all things. They share certain properties, such as edible/inedible, and certain fields, such as the initial appearance and the description.

When we created the wicker cage, we didn’t call it a thing – we called it a container, instead. A container is a kind of thing. It has all the properties of a thing, but it has additional properties that belong specifically to containers.

Similarly, when we created the little bird, we called it an animal. An animal is a kind of person, and a person is a kind of thing. An animal has all the properties of things, plus the properties of people, plus the properties of animals.

You can get a detailed look at all of the kinds in the game by going to Index, to Kinds, and then dragging down. You can also see every representative of every kind listed there – so you can see the wicker cage listed under containers, and also under things.

all the kinds in the game

You are not limited to the kinds that are pre-populated in Inform. You can create new kinds from any of the existing kinds, or from any new kinds that you create.

In this case, let’s create a new kind of thing called treasure to make treasure scoring easier. By transferring all the rules from the bars of silver onto the new treasure kind, we can create a template that will affect any other treasure we want to create.

A treasure is a kind of thing. A treasure can be scored or unscored. A treasure is usually unscored.

After taking a treasure (called the current treasure):
    if the current treasure is unscored:
        increase the score by 5;
        now the current treasure is scored;
    continue the action.

Some bars of silver are a treasure. The bars of silver are in Low N/S Passage.

Some precious jewelry is a treasure. The precious jewelry is in Low N/S Passage.

Some rare coins are a treasure. The rare coins are in Low N/S Passage.

And that will work just fine.

lots of treasure

Note that the words “the current treasure” could be anything – “the loot”, “the grabbed thing”, “your hippopotamus”. It’s just a temporary variable to indicate which treasure you mean.

Why specify “(called the current treasure)” at all? Why not just say “if the treasure is unscored” and “now the treasure is scored”?

First, “now the treasure is scored” won’t compile. The game has to know which treasure should be scored. It won’t pick one at random.

Second, “if the treasure is unscored” is equivalent to “if a treasure is unscored” – which is true if any treasure is unscored, not just the one being handled. This will compile, but it can lead to some truly devious bugs. Being specific is better.

Ending the Game

The full mechanics for ending a game of Adventure are fairly complex, seeing as they involve orange smoke. But most games do need an end, and since this is a quick-start guide, this will be a quick-end game.

Like every other instruction to be carried out during play, ending the game needs to be built into a rule. I’m going to build it into our existing treasure setup, just to make life easy.

 After taking a treasure (called the current treasure):
    if the current treasure is unscored:
        increase the score by 5;
        now the current treasure is scored;
        if the score is 15:
            end the story saying “Hooray, you win!”;
    continue the action.

There are some fine-tuned variations available in endings, such as the difference between ending the story (which can be reversed) and ending the story “finally” (which cannot, and potentially reveals hidden menu options to the player), but these are beyond the scope of this article.

Further Reading

The most helpful chapter for follow-up reading is Chapter 4, which covers building new kinds and goes into extensive detail about how to use them. Other helpful sections for this lesson include:

§2.12 Use options
§3.5 Kinds
§3.6 Either-or properties
§3.7 Properties depend on kind
§8.4 Change of either/or properties
§8.15 Calling names
§9.2 Awarding points
§9.4 When play ends

Bookmark the permalink.

2 Comments

  1. Keep up with the fantastic tutorials if possible. I realize it is a lot of work putting it on the internet. Your efforts are appreciated by the IF community.

Leave a Reply to Mark Anderson Cancel reply

Your email address will not be published. Required fields are marked *