Inform 7 Home Page / Documentation


§24.2. Debugging features to use in source

The TEST command is an extremely useful way of managing a story and continuing to verify that it does everything we want. We can create new test commands of the form

Test me with "up / kill captain eo".
Test eo with "zap eo" holding the ray gun.
Test dinner with "eat bread / eat soup / eat butter" in the Ship Cafeteria.

and we are free to have as many of these tests as we would like. Test commands can call other tests, as well, so we might have a test command such as

Test megatest with "test me / test eo".

A word of warning: if the first command in the test is "again", that will likely repeat the TEST command, sending Inform round in circles forever.

For complicated objects and commands, sometimes it's a good idea to develop the test commands at the same time that we're writing the source code itself. Each time we add a new rule or piece of behavior, we also add to that object's special test command something that will put that new feature to the test. This means that we can keep running the test command as we work and verify that everything is behaving as expected.

Sometimes we need to get a look at what is happening within the source itself. Many of the most annoying bugs come about because we're making some assumptions about what's true in the story world that differ from Inform's assumptions. When that happens, we may need to add something to the source to check that the variables are set to what we think, that certain parts of the source are being reached, and so on.

For instance, suppose we have a phrase like this:

To say key score:
    let count be the number of keys which are not carried by the player;
    if count is greater than 2 and the player is timid:
        say "You're still missing a lot of keys, bucko!"

Now, we expect this to print something, but perhaps it's not doing so when we had anticipated that it would. At some point when we think the count is greater than 2 and the player is timid, at least one of those things is not true. An easy way to check up on this is to add a showme line to the source, like so:

To say key score:
    let count be the number of keys which are not carried by the player;
    showme count;
    if count is greater than 2 and the player is timid:
        say "You're still missing a lot of keys, bucko!"

and this will then check the relevant number and print it to screen when this phrase is called, like so

"count" = number: 1

In this case, it looks like the count is not high enough to trigger the text, so we can concentrate on working out why that might be. Maybe we didn't correctly define something as a key, for instance.


arrow-up.png Start of Chapter 24: Testing and Debugging
arrow-left.png Back to §24.1. Checking against the Index
arrow-right.png Onward to §24.3. High-level debugging commands