§10.10. Magic (Breaking the Laws of Physics)

Every previous section of this chapter has been about adding further realism constraints to Inform, to give it a more advanced understanding of physics (and chemistry). But Inform has plenty of physical laws built into it already, even if they are more mundane: inanimate objects do not spontaneously move or change, one solid object cannot pass through another, there are opaque barriers through which light cannot pass, and so on. These rules stop many attempted actions. (GO EAST - "The oak door is closed." GET EMERALD - "You can't, since the glass display case is in the way.")

In the real world, physics is not negotiable. ("Gravity: it's not just a good idea, it's the law.") But in stories, magic can sometimes happen, and in these examples some of the rules built into Inform are waived in special circumstances, which in effect cancel certain physical laws. Very many other magical tricks could be achieved: if you want to make a given command work despite realism constraints, try typing ACTIONS - a testing command which reveals what is happening behind the scenes - and then typing the command you want. This should reveal which named rule is stopping it: you can then try suspending that rule, and seeing if the effect now works.

* See Magic Words for ways to create new single-word spell commands


arrow-up.pngStart of Chapter 10: Physics: Substances, Ropes, Energy and Weight
arrow-left.pngBack to §10.9. Heat
arrow-right.pngOnward to §10.11. Mathematics

*ExampleMagneto's Revenge
Kitty Pryde of the X-Men is able to reach through solid objects, so we might implement her with special powers that the player does not have...

*ExampleInterrogation
A wand which, when waved, reveals the concealed items carried by people the player can see.

Suppose we want to have a machine in our game that can transmute one item into another, similar object with different properties: a bag of jelly beans into a bag of jewels, for instance. Thus each item will be associated with some number of equivalents -- the other objects it can turn into. This is a handy use for group relations:

paste.png "Transmutations"

Workshop is a room.

Transmutation relates things to each other in groups. The verb to become means the transmutation relation.

Definition: a thing is transmutable if it becomes more than one thing. [* It always becomes itself.]

A thing can be valuable. Something valuable called a bag of jewels is carried by the player. It becomes the bag of gunpowder and the bag of jelly beans.

A thing can be dangerous. The bag of gunpowder is a dangerous thing.

The bag of jelly beans is an edible thing.

The machine is fixed in place in the workshop.

The can't insert into what's not a container rule does nothing when inserting something into the machine.

Check inserting something which is not transmutable into the machine:
    instead say "You can't transmute that."

To decide which thing is new form of (obj - edible thing): decide on a random valuable thing which becomes obj.

To decide which thing is new form of (obj - dangerous thing): decide on a random edible thing which becomes obj.

To decide which thing is new form of (obj - valuable thing): decide on a random dangerous thing which becomes obj.

Carry out inserting something into the machine:
    now the noun is nowhere;
    now the player carries the new form of the noun.

Report inserting something edible into the machine:
    say "The machine clicks, whirrs, and spits out [a new form of the noun]. You're rich!";
    rule succeeds.

Report inserting something dangerous into the machine:
    say "The machine clicks, whirrs, and in a shower of flavor crystals, spits out [a new form of the noun].";
    rule succeeds.

Report inserting something valuable into the machine:
    say "The machine clicks, whirrs, and with a violent roar, spits out [a new form of the noun].";
    rule succeeds.

    Test me with "i / put jewels in machine / i / put gunpowder in machine / i / put beans in machine".

In this example we have only defined a single set of transmutable objects, but we could easily expand to include other groups.

(Thanks to Jesse McGrew for proposing this example.)

*ExampleTransmutations
A machine that turns objects into other, similar objects.

Suppose we want to have a machine in our game that can transmute one item into another, similar object with different properties: a bag of jelly beans into a bag of jewels, for instance. Thus each item will be associated with some number of equivalents -- the other objects it can turn into. This is a handy use for group relations:

paste.png "Transmutations"

Workshop is a room.

Transmutation relates things to each other in groups. The verb to become means the transmutation relation.

Definition: a thing is transmutable if it becomes more than one thing. [* It always becomes itself.]

A thing can be valuable. Something valuable called a bag of jewels is carried by the player. It becomes the bag of gunpowder and the bag of jelly beans.

A thing can be dangerous. The bag of gunpowder is a dangerous thing.

The bag of jelly beans is an edible thing.

The machine is fixed in place in the workshop.

The can't insert into what's not a container rule does nothing when inserting something into the machine.

Check inserting something which is not transmutable into the machine:
    instead say "You can't transmute that."

To decide which thing is new form of (obj - edible thing): decide on a random valuable thing which becomes obj.

To decide which thing is new form of (obj - dangerous thing): decide on a random edible thing which becomes obj.

To decide which thing is new form of (obj - valuable thing): decide on a random dangerous thing which becomes obj.

Carry out inserting something into the machine:
    now the noun is nowhere;
    now the player carries the new form of the noun.

Report inserting something edible into the machine:
    say "The machine clicks, whirrs, and spits out [a new form of the noun]. You're rich!";
    rule succeeds.

Report inserting something dangerous into the machine:
    say "The machine clicks, whirrs, and in a shower of flavor crystals, spits out [a new form of the noun].";
    rule succeeds.

Report inserting something valuable into the machine:
    say "The machine clicks, whirrs, and with a violent roar, spits out [a new form of the noun].";
    rule succeeds.

    Test me with "i / put jewels in machine / i / put gunpowder in machine / i / put beans in machine".

In this example we have only defined a single set of transmutable objects, but we could easily expand to include other groups.

(Thanks to Jesse McGrew for proposing this example.)

*ExampleAccess All Areas
The Pointy Hat of Liminal Transgression allows its wearer to walk clean through closed doors.