Inform 7 Home Page / Documentation
§10.6. Ropes
Ropes, chains and similar long, thin, bendable items present three problems: they are like a liquid in that (unless unbreakable) they can be divided arbitrarily into smaller and smaller portions of themselves, they can be in two or more places at once (even in two or more rooms at once), and they can be tied down at either or both ends, allowing them to occupy an uneasy state in between being "portable" and "fixed in place". Even when all this is simulated, they allow us to pull on one end and so to exert force at the other - allowing action-at-a-distance which Inform's realism rules would ordinarily forbid. Ropes are hard. And it is very difficult to imagine everything a player might try when given a fully practical rope with which to solve puzzles.
Snip solves the divisibility question, allowing string to be cut or retied into lengths of any size, with all the consequences for describing and understanding that this entails.
Otranto provides a lengthy but straightforward approach to the other rope-related issues, subject to the simplifying assumptions that a rope is indivisible, has about the length of the distance between two adjacent rooms, and cannot be tied to another rope.
Start of Chapter 10: Physics: Substances, Ropes, Energy and Weight | |
Back to §10.5. Volume, Height, Weight | |
Onward to §10.7. Electricity and Magnetism |
ExampleOtranto |
The range of things one might want to do with a rope in a work of interactive fiction is fairly overwhelming. One might, in theory, swing from ropes; use them to tie containers shut; cut them up into smaller ropes; tie them together into longer ropes; employ them as fuses; bind other characters with them, or the player character.
Our rope implementation is, by these lights, reasonably simple, but it does account for the possibility of tying and untying both ends; using ropes to descend into lower rooms; pulling objects tied to the far end of the rope; and dragging objects from place to place.
We start by coming up with a rope.
Definition: a thing is nonrope if it is not a rope. [The perfect idiocy of this statement notwithstanding, having a shortcut will come in very handy later]
Attachment relates things to each other in groups. The verb to be stuck to means the attachment relation.
Definition: a thing is tied if the number of things stuck to it is greater than 1.
Definition: a rope is free if the number of nonrope things stuck to it is less than 2.
Definition: a thing is hindering if it is stuck to the noun and it is not within the location.
A thing can be round or unevenly shaped. A thing is usually round.
Definition: something is anchored if it is fixed in place or it is scenery or it is part of an anchored thing.
Definition: something is draggable if it is not had by the player and it is not the player and it is not anchored.
Now, we want a rope to be described in terms of the way it is tied, when it's described in a room description.
Rule for writing a paragraph about a rope (called the coil):
if the coil is stuck to something which is in a room (called the next room) which is not the location:
let the way be the best route from the location to the next room;
if the way is up or the way is down:
say "[The coil] runs [way] into [the next room].";
otherwise:
say "[The coil] snakes across the floor [way] towards [the next room].";
otherwise:
say "There is [a coil] here[if the coil is stuck to a visible nonrope thing], tied to [the list of nonrope visible things which are stuck to the coil][end if]."
To decide what room is the home of (item - a thing):
if item is a door:
let front cut be the number of moves from the location to the front side of the item;
let back cut be the number of moves from the location to the back side of the item;
if front cut is -1, let front cut be 999;
if back cut is -1, let back cut be 999;
if the location encloses the item, decide on the location;
if front cut is greater than back cut, decide on the back side of the item;
decide on the front side of the item;
decide on the location of the item.
Rule for writing a paragraph about a nonrope thing (called the anchor) which is stuck to a rope (called the coil):
if the coil is in an adjacent room:
let the next room be the home of the coil;
let the way be the best route from the location to the next room;
if the way is up or the way is down:
say "[The coil] runs [way] from [the anchor] into [the next room].";
otherwise:
say "From [the anchor] runs [a coil], heading off toward [the way].";
otherwise:
if the coil is stuck to something which is not visible,
say "[The coil] is tied to [the anchor][if the coil is stuck to something in an adjacent room (called the next room)], and from there runs off towards [the next room][end if]."
We need a way to account for it when it's being carried, as well.
After printing the name of a rope (called the tied object) while taking inventory:
if something nonrope is stuck to the tied object:
say " (attached to [the list of nonrope things which are stuck to the tied object])";
otherwise:
say " (with both ends free)".
And, indeed, whenever the player examines a rope, we should see what's connected.
Instead of examining a rope (called the cord) when something is stuck to the cord:
say "[The noun] is tied to [the list of secondary things which are stuck to the noun]."
Similarly, any time the player looks at something tied to a rope.
After examining the player when the player is stuck to something which is not the player:
say "You're currently lashed to [the list of secondary things stuck to the noun]."
After examining something which is stuck to something secondary:
say "[The noun] is currently attached to [the list of secondary things stuck to the noun]."
We also need to make sure that the rope can be interacted with properly even when it's partly in the next room.
After deciding the scope of the player:
if something stuck to a rope (called the coil) is in the location, place the coil in scope.
A reaching inside rule:
if the noun is a rope:
let the anchor be a random visible thing stuck to the noun;
if the anchor is not the noun:
if the anchor is touchable, allow access.
Now tying:
Before tying something to a rope:
if the noun is stuck to the second noun, say "[The noun] and [the second noun] are already tied together." instead;
if the second noun is not free, say "[The second noun] has no ends free." instead;
if the noun is round, say "You can't realistically tie anything to [the noun]." instead.
Instead of tying a rope to something:
try tying the second noun to the noun.
Instead of tying something to a rope:
now the noun is stuck to the second noun;
say "You loop [the second noun] around [the noun] and knot firmly."
Instead of tying something to a nonrope tied thing:
let the coil be a random rope stuck to the second noun;
try tying the noun to the coil.
Instead of tying a nonrope tied thing to something:
let the coil be a random rope stuck to the noun;
try tying the second noun to the coil.
Instead of tying a free nonrope thing to a free nonrope thing:
if the player carries a free rope (called the coil):
try tying the noun to the coil;
if the noun is stuck to the coil and the coil is free:
try tying the second noun to the coil;
otherwise:
say "You lack the requisite spare rope."
Understand "untie [something] from [something]" as untying it from. Understand "untie [something]" as untying it from.
Rule for supplying a missing second noun while untying something from:
if the number of secondary things stuck to the noun is 0, say "[The noun] is already entirely free." instead;
if the noun is a rope:
if the number of touchable nonrope things which are stuck to the noun > 1:
say "You'll have to say which thing you want to untie [the noun] from.";
rule fails;
otherwise:
if the number of touchable nonrope things stuck to the noun is 0, say "You can't reach [the random nonrope thing stuck to the noun]." instead;
let the tied object be a random touchable nonrope thing which is stuck to the noun;
say "(from [the tied object])[line break]";
now the second noun is the tied object;
otherwise:
if the noun is stuck to a rope (called the tied object):
say "(from [the tied object])[line break]";
now the second noun is the tied object.
Before untying a rope from something: try untying the second noun from the noun instead.
Before untying something from a rope:
if the second noun is not held:
say "(first picking up [the second noun])[line break]";
try taking the second noun.
Check untying it from:
unless the noun is stuck to the second noun or the second noun is stuck to the noun,
say "[The noun] and [the second noun] are already not tied together." instead.
Carry out untying it from:
now the noun is not stuck to the second noun.
Another part of the fun of a rope is that you can drag things from another room:
Before pulling something anchored: say "[The noun] is firmly anchored." instead.
Instead of pulling something tied:
if the noun is unmentioned:
say "The impulse is transmitted to [the list of pullable things stuck to the noun].";
repeat with item running through pullable things stuck to the noun:
say "[item]: [run paragraph on]";
try pulling the item;
if the noun is a rope and the noun is not within the location:
if the number of nonrope hindering things is 0, move the noun to the location;
otherwise:
continue the action.
Before pulling something which is not visible:
if the noun is anchored:
say "[The noun] resists, for whatever reason." instead;
otherwise:
let space be the holder of the noun;
let way be the best route from the space to the location;
if the way is a direction:
move the noun to the location;
say "[The noun] [if the way is up]rises[otherwise]slides[end if] into view." instead;
otherwise:
move the noun to the location;
say "[The noun] slides into view." instead.
Definition: a thing is secondary if it is not the noun. Definition: a thing is pullable if it is not the noun and it is not the player.
A player who is tied to things should also have some restrictions on his ability to move.
Before going a direction (called the way) when the player has something (called the link) which is stuck to something anchored (called the anchor):
let the next room be the home of the anchor;
if the next room is not a room, continue the action;
if the next room is the location:
if the link is stuck to at least two anchored things,
say "You can't go far while you're carrying [the link] tied to [the list of anchored things stuck to the link]." instead;
otherwise:
let the safe way be the best route from the location to the next room;
if the safe way is the way:
if the player is not stuck to the anchor, say "(coiling up your rope again as you go...)";
otherwise:
if the safe way is a direction,
say "While you have [the link] you can't really head any direction but [best route from the location to the next room]." instead;
otherwise say "You're tied up here." instead.
Before going a direction (called the way) when the player is stuck to something anchored (called the anchor):
let the next room be the home of the anchor;
if the next room is not a room, continue the action;
if the next room is the location:
if the player is stuck to at least two anchored things,
say "You can't go far while you're tied to [the list of anchored things stuck to the player]." instead;
otherwise:
if the best route from the location to the next room is the way:
say "(coiling up your rope again as you go...)";
otherwise:
say "Your attachments prevent you going any way but [best route from the location to the next room]." instead.
Sometimes, if the player is tied to a movable object, the moved object will move with him.
After going somewhere when the player has something (called the link) which is stuck to something draggable:
if the player is not stuck to the link:
say "You drag along behind you [the list of draggable things which are stuck to the link].";
now every draggable thing which is stuck to the link is in the location;
continue the action.
Report going somewhere when the player is stuck to something draggable:
say "You drag along behind you [the list of draggable things which are stuck to the player].";
now every draggable thing which is stuck to the player is in the location.
And now the actual game and puzzles.
The Fallow Field is a room. "The very land is gloomy, the earth plowed into untended rows that yield no fruit, shadowed by the castle to the north. A chasm, no doubt the product of some upheaval of the earth, opens before your feet.". An oak stump is fixed in place in the Field. "From an oak stump, a few hopeful shoots grow." A hempen rope is a rope in the field. It is stuck to the oak stump and the wooden chest. The stump is unevenly shaped.
The Chasm is below the Field. "Your person is most uncomfortably pressed on every side by the closeness of the walls; to which you may add as a further inconvenience, that the irregularity of the floor making it difficult to walk upright." An iron key is in the Chasm. "An iron key nestles in the cleft of earth, its age indicated by its implausibly great size."
The wooden chest is a unevenly shaped closed openable container in the Chasm. The description of the wooden chest is "A handsome, solid case not long committed to its dank enclosure, or it would long since have rotted." Rule for printing the name of the wooden chest when the chest is not handled: say "deadweight". Understand "dead" or "weight" or "deadweight" as the chest. Before pulling the wooden chest: now the chest is handled.
In the chest is a heavy dagger. The description of the dagger is "Set with red jewels and of a wicked aspect."
Before going down from the Field when the player is not stuck to something anchored:
say "You don't quite dare simply leap into the darkness without some anchor." instead.
Before going down from the Field:
let anchor be a random anchored thing which is stuck to the player;
say "You lower yourself gingerly, hoping that [the anchor] holds your weight..."
Before going up from the Chasm:
if the player cannot touch a rope which is stuck to an anchored thing which is in the Field, say "And how, precisely, do you mean to do that?" instead.
The Castle Hall is north of the Field. "All is desolate: the great hall has no roof, nor is there any glass in the windows. A staircase without banister ascends inside the wall to a musician's gallery without song."
The Musician's Gallery is above the Castle Hall. "Of its former cheery aspect only this remains to the Gallery: that chevrons of red and yellow are painted on the wall. But as these are streaked with rain and grime, the banister pulled away, the roof open to the sky, and the corners made a nesting place for birds, the consolation thereby afforded is but slight."
The pointed door is north of the Musician's Gallery and south of the Sinister Attic. It is a closed locked openable door. "A pointed door of particularly grim and uninviting aspect leads north." The pointed door is lockable and unevenly shaped. The description of the pointed door is "A door coming to a gothic point and fitted with iron fittings of great strength. The handle looks particularly well-attached." The iron key unlocks the pointed door.
A rule for reaching inside the Musician's Gallery:
allow access.
A rule for reaching inside the Sinister Attic:
allow access.
Instead of opening the pointed door for the first time:
say "When you rattle at the door, there arises from beyond a terrible shrill noise as though something beyond exults in its imminent release."
After opening the trapped pointed door when the player can see the pointed door:
say "Thousands of bats fly from the pointed door, attacking you!";
end the story.
After opening the pointed door when the player cannot see the pointed door: now the pointed door is untrapped; continue the action.
The pointed door can be trapped or untrapped. The pointed door is trapped.
Before pulling the pointed door: try opening the pointed door instead.
After going to the sinister attic:
say "You have arrived at the goal of your quest!";
end the story finally.
Test me with "x rope / pull rope / get chest / untie rope from chest / tie rope to me / down / get key / up / untie rope from stump / north / up / unlock pointed door with key / open it / tie rope to door / down / pull rope / up / north".
Test death with "x rope / pull rope / get chest / untie rope from chest / tie rope to me / down / get key / up / untie rope from stump / north / up / unlock pointed door with key / open it / g"
ExampleSnip |
Length is a kind of value. 30 inch specifies a length. 20 in specifies a length. 50 inches specifies a length.
A string is a kind of thing. A string has a length. The length of a string is usually 36 inches.
Before printing the name of a string, say "[length] piece of ". Rule for printing the plural name of a string: say "[length] pieces of string".
Understand the command "cut" as something new. Understand "cut [length] from/off [something]" as trimming it by (with nouns reversed). Understand "cut [something] by [length]" as trimming it by. Understand the command "trim" as "cut".
Trimming it by is an action applying to one thing and one length.
Check trimming it by:
if the length understood is 0 inches, say "You're approaching Zeno's string at this point." instead;
if the length understood is greater than the length of the noun, say "[The noun] is only [length of the noun] long to start with." instead;
if the length understood is the length of the noun, say "[The noun] is already exactly [length of the noun] long." instead.
Carry out trimming it by:
now the length of the noun is the length of the noun minus the length understood;
let the other half be a random string in the string repository;
now the length of the other half is the length understood;
move the other half to the player.
Report trimming it by:
reset string lengths; [we will define this in a moment; it helps guarantee that our descriptions of the strings are correct when we write the output list]
say "You now have [a list of strings carried by the player]."
Understand "cut [something] in half" as halving. Halving is an action applying to one thing.
Carry out halving:
let half measure be the length of the noun divided by 2;
now the length understood is half measure;
try trimming the noun by half measure.
This fudges slightly, since an odd-length string will be divided into uneven halves. Keeping track of fractional inches would complicate matters, though, so let's assume for now that this doesn't matter.
Since our initial string is 36 inches long and it is impossible for the player to divide it into pieces smaller than an inch each, we need a total of 36 items to represent all the string-bits: one that the player carries at the outset, and 35 others. We should bear in mind that it is usually a good idea to use the smallest number of spare objects we can get away with: writing a game that required 1000 strings in the string repository would place silly demands on the resources of the system, so it's best to avoid that sort of thing if possible.
Now with a bit of fiddling we can also teach Inform to recognize descriptors such as "the shortest string":
Ordinariness is a kind of value. The ordinarinesses are longest, medium, shortest. A string has an ordinariness. Understand the ordinariness property as referring to a string.
Definition: a string is small if its length is 2 in or less. Definition: a string is large if its length is 20 in or more.
To reset string lengths:
let upper measure be the length of the largest visible string;
let lower measure be the length of the smallest visible string;
repeat with item running through strings:
now the ordinariness of the item is medium;
if the length of the item is the upper measure, now the item is longest;
if the length of the item is the lower measure, now the item is shortest.
After reading a command:
if the player's command includes "shorter", replace the matched text with "shortest";
if the player's command includes "longer", replace the matched text with "longest".
Instead of tying a string to a string:
move the second noun to the string repository;
now the length of the noun is the length of the noun plus the length of the second noun;
decrease the length of the noun by 1 inch;
say "You end up with [a noun], as some is taken up by the knot."
This is still a little incomplete because we cannot refer to strings by their lengths, as in "the 2 inch string" and so on. To do this, we borrow a line from the chapter on Understanding:
Test me with "trim string by 4 in / cut longer string in half / cut longest string in half / cut shortest string in half / g / g / tie longest string to shortest string / tie longest string to medium string / i / x 16 inch string / drop 8 inch string / i".