Rules of Attraction
Example 346
★Often we have some salient features of an object that we want to make sure the player notices whenever looking at the item in a room or in inventory. At other times, we may prefer to allow the name of the item to be printed bare. So for instance:
"Rules of Attraction"
A metal form is a kind of thing. A magnet is a kind of metal form.
Every turn:
repeat with item running through nonmagnetic metal forms which are not part of something:
if item is in a container which contains a magnet (called attractor):
say "[The item] sticks to [the attractor].";
now the item is part of the attractor.
The horseshoe magnet is a magnet carried by the player. The nail is a metal form carried by the player. The Barn is a room. In the Barn is a bucket. In the bucket is a metal form called the iron hook.
Definition: a thing is nonmagnetic if it is not a magnet.
Rule for printing room description details of a magnet (called attractor): if something is part of the attractor, say " (stuck to which [is-are the list of things which are part of the attractor])".
After printing the name of a magnet (called attractor) while taking inventory:
if something is part of the attractor, say " (stuck to which [is-are the list of things which are part of the attractor])".
Before taking a touchable thing which is part of a magnet (called attractor):
move the noun to the holder of the attractor.
Test me with "i / put horseshoe in bucket / look / get horseshoe / i / drop horseshoe / i / look / get all / put all in bucket / i / x magnet / get nail / i".
Test me with "i / put horseshoe in bucket / look / get horseshoe / i / drop horseshoe / i / look / get all / put all in bucket / i / x magnet / get nail / i".
Barn
You can see a bucket (in which is the iron hook) here.
>(Testing.)
>[1] i
You are carrying:
a horseshoe magnet
a nail
>[2] put horseshoe in bucket
You put the horseshoe magnet into the bucket.
The iron hook sticks to the horseshoe magnet.
>[3] look
Barn
You can see a bucket (in which is a horseshoe magnet (stuck to which is the iron hook)) here.
>[4] get horseshoe
Taken.
>[5] i
You are carrying:
a horseshoe magnet (stuck to which is the iron hook)
a nail
>[6] drop horseshoe
Dropped.
>[7] i
You are carrying:
a nail
>[8] look
Barn
You can see a horseshoe magnet (stuck to which is the iron hook) and a bucket (empty) here.
>[9] get all
horseshoe magnet: Taken.
bucket: Taken.
>[10] put all in bucket
horseshoe magnet: Done.
nail: Done.
The nail sticks to the horseshoe magnet.
>[11] i
You are carrying:
a bucket
a horseshoe magnet (stuck to which are the nail and the iron hook)
>[12] x magnet
You see nothing special about the horseshoe magnet.
>[13] get nail
Taken.
>[14] i
You are carrying:
a nail
a bucket
a horseshoe magnet (stuck to which is the iron hook)
You can see a bucket (in which is the iron hook) here.
>(Testing.)
>[1] i
You are carrying:
a horseshoe magnet
a nail
>[2] put horseshoe in bucket
You put the horseshoe magnet into the bucket.
The iron hook sticks to the horseshoe magnet.
>[3] look
Barn
You can see a bucket (in which is a horseshoe magnet (stuck to which is the iron hook)) here.
>[4] get horseshoe
Taken.
>[5] i
You are carrying:
a horseshoe magnet (stuck to which is the iron hook)
a nail
>[6] drop horseshoe
Dropped.
>[7] i
You are carrying:
a nail
>[8] look
Barn
You can see a horseshoe magnet (stuck to which is the iron hook) and a bucket (empty) here.
>[9] get all
horseshoe magnet: Taken.
bucket: Taken.
>[10] put all in bucket
horseshoe magnet: Done.
nail: Done.
The nail sticks to the horseshoe magnet.
>[11] i
You are carrying:
a bucket
a horseshoe magnet (stuck to which are the nail and the iron hook)
>[12] x magnet
You see nothing special about the horseshoe magnet.
>[13] get nail
Taken.
>[14] i
You are carrying:
a nail
a bucket
a horseshoe magnet (stuck to which is the iron hook)