Using “Instead”

The easiest way to start customizing how Inform handles actions is to write a few Instead rules. We’re going to create a bubbling beaker of magic potion and then use a couple of Instead rules on it. Inform already has actions for drinking and taking. The command DRINK POTION, however, produces the output, “There’s nothing suitable to drink here,” which is not what we want in this particular case. TAKE POTION will allow the player to pick up the potion, and that might not be what we want either, if the potion is a liquid in a container. Here’s how to customize Inform’s default behavior using Instead rules:

The bubbling potion is on the stone table. The description is "The bubbling beaker is full of noxious-looking yellow potion." Understand "beaker", "yellow", and "noxious" as the bubbling potion.

Instead of drinking the bubbling potion:
        say "You take a tiny sip, but it smells awful, so you put it down again."

Instead of taking the bubbling potion:
        say "If you try to carry it around, you'll only spill it and stain your clothes."

The response above to TAKE POTION will prevent the player from picking up the potion, because the Instead rule will stop the taking action in its tracks. We could do the same thing by saying, “The bubbling potion is fixed in place”, but that produces a boring message when the player tries TAKE POTION. The code above will give a more interesting message.

Likewise, if the player tries DRINK POTION, a new message will be printed out by the Instead rule in place of the default message. Nothing will actually happen in the model world as a result of this command — but if we wanted something to happen, we could just add it to the Instead rule. In an extreme case, we might want to do something like this:

Instead of drinking the bubbling potion:
        say "Your first tiny sip of the bubbling potion causes your whole body to be wracked by horrible spasms!";
        end the story saying "How inconvenient. You have died!"

Almost anything we might want to happen in the model world can be tucked into an Instead rule like this. To understand how Instead rules work, we need to delve deeper into Inform’s action processing.