How do I have an instead function apply for only a specified amount of turns?

93 Views Asked by At

I am new to inform 7, and I want to undo an instead command that I only wanted to apply earlier. How do I do so? (I want this to happen after an event, using an after statement.)

1

There are 1 best solutions below

0
Lynn On

Suppose we have a little story with an instead-rule.

"Lasers" by Lynn

The Lab is a room. "To the east lies the vault. If only there weren't
    deadly lasers separating you from it."

The Vault is east from the Lab. "You made it!"
Instead of going east from the Lab:
    say "A lattice of red-hot laser beams blocks your path."

We'd like to "disable" this instead-rule once a certain action happens. This can happen from inside an after-rule, as you suggest, but also in any other kind of rule.

We could add something like this:

Lasers safe is a truth state that varies.

The dial is a device in the Lab. It is fixed in place and switched on.
Carry out switching off the dial: now lasers safe is true.
After switching off the dial: say "The lasers cool down and turn harmless."

And now, instead of actually undoing our instead-rule definition at run-time, we narrow the condition of its definition down so that it is "defused", never to apply again, once lasers safe becomes true.

So we reprogram the instead-rule to read:

Instead of going east from the Lab when lasers safe is false:
    say "A lattice of red-hot laser beams blocks your path."

Once nice thing about this pparoach is that we can now even "redo" our "undo": a simple now lasers safe is false returns the instead-rule's old behavior.


This solution is generic: you can always define a global truth-value that disables an instead-rule like this.

Of course, it is even easier to simply write some thing like:

  • Instead of [action] when the [noun] is (not) [adjective]:

  • Instead of [action] when we have (not) [verb]ed the [noun]:

In our case, we are free to write:

Instead of going east from the Lab when the dial is switched on:
    say "A lattice of red-hot laser beams blocks your path."

or something like:

Instead of going east from the Lab when we have not pushed the red button:
    say "..."

See §9.12. Actions as conditions.