Skip to content

Instantly share code, notes, and snippets.

@rdnlsmith
Created October 26, 2022 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdnlsmith/9c44dcc34f84b5254e3e0a76d149cb72 to your computer and use it in GitHub Desktop.
Save rdnlsmith/9c44dcc34f84b5254e3e0a76d149cb72 to your computer and use it in GitHub Desktop.
Inform Demo

Inform Demo

This is a small example program written in the Inform programming language, for purposes of a post on my blog. See the post for further explanation.

"Inform Demo" by "Daniel Smith"
Include Locksmith by Emily Short.
The Study is a dark room. "Not quite cramped, but not expansive either; a stately desk pushed against the far wall fills most of the space. An aging wheeled chair stands vigil before it."
The Featureless Void is a room. "You are surrounded by bright white nothingness in all directions."
The wall and the floor are scenery in the study. The floor is a supporter.
The power outlet is scenery in the study. The description is "A standard American power outlet[if the lamp is plugged]. [The lamp] is currently plugged in[end if]."
The stately desk is scenery in the Study. Understand "table" as the desk. It is an enterable supporter. The description is "Standing proud and squarish, the desk appears worn yet still elegant to look upon. Its dark walnut surface is covered with innumerable faint scuffs and scrapes denoting its many years of service. There is a wide, shallow drawer embedded in front[if the drawer is open], which is currently open[end if].".
A drawer is part of the stately desk. The description is "Like the rest of the desk, the drawer is faced with walnut and worn from age. It is adorned with an antique-brass handle.". The drawer is a closed openable container.
Instead of searching the drawer when the drawer is closed, try opening the drawer.
Instead of searching the desk:
try searching the drawer;
continue the action.
A thing can be examined or unexamined. A thing is usually unexamined.
After examining something:
now the noun is examined.
The brass key is in the drawer. The description is "[The brass key] is small, with an antique finish[if the wooden door is examined]. It looks like it could fit the lock on [the wooden door][end if].".
The wheeled chair is scenery in the Study. Understand "desk chair", "leather", "brown", "imprint", and "padding" as the wheeled chair. It is an enterable supporter. The description is "The chair is upholstered with brown leather, cracked with age. Its usual occupant has left an imprint in the padding.".
Instead of pushing or pulling the wheeled chair, say "[if the player is on the chair]You glide[otherwise]It glides[end if] easily across the floor.". Instead of taking the wheeled chair, say "It's rather too bulky to carry around. Besides, it would be a shame to separate it from the desk.".
Spinning is an action applying to one thing. Understand "spin [something]" as spinning.
Instead of spinning something, say "That wasn't designed to be spun."
Instead of spinning the wheeled chair, say "The chair spins around, creaking slightly[if the player is on the wheeled chair]. You feel a little dizzy[end if]."
Implicit spinning is an action applying to nothing. Understand "spin" as implicit spinning.
Instead of implicit spinning:
if the player is on the wheeled chair:
try spinning the wheeled chair;
otherwise:
say "Spin what?".
The lamp is on the desk. The printed name of the lamp is "desk lamp". Understand "desk lamp", "stainless", "steel", "metal", "shade", "lampshade", "cone", "stem", and "light" as the lamp. The lamp is a switched on device. The lamp is lit. The lamp can be plugged or unplugged. The lamp is plugged. The initial appearance of the lamp is "A metal desk lamp is the only light source in the room. It illuminates the desk, but not much else.". The description is "The desk lamp is made from stainless steel. It has a conical metal shade with a switch on the back. A flexible stem connects the shade to the base.".
To decide if the lamp is operable:
if the lamp is plugged and the lightbulb is in the socket:
decide yes;
otherwise:
decide no.
Before taking the lamp:
say "(first unplugging [the lamp])[command clarification break]";
try unplugging the lamp.
Carry out switching off the lamp:
now the lamp is not lit.
Carry out switching on the lamp:
if the lamp is operable:
now the lamp is lit.
After switching on the lamp when the lamp is unplugged:
Say "You switch [the lamp] on. However, it is unplugged.".
After switching on the lamp when the lamp is plugged and the lightbulb is not in the socket:
say "You switch [the lamp] on. However, the bulb is missing."
Plugging is an action applying to one thing. Understand "plug in [something]" as plugging.
Carry out plugging the lamp:
now the lamp is plugged;
if the lamp is switched on and the lamp is operable:
now the lamp is lit.
Report plugging the lamp:
Say "You plug in [the lamp][if the lamp is switched on and the lamp is operable]. The bulb flares to life[end if].".
Instead of plugging the lamp when the lamp is plugged:
Say "[The lamp] is already plugged in.".
Unplugging is an action applying to one thing. Understand "unplug [something]" as unplugging.
Carry out unplugging the lamp:
now the lamp is unplugged;
now the lamp is not lit.
Report unplugging the lamp:
Say "You unplug [the lamp][if the lamp is switched on and the lightbulb is in the socket]. The bulb flickers out[end if].".
Instead of unplugging the lamp when the lamp is unplugged:
Say "[The lamp] is already unplugged.".
Instead of plugging or unplugging something that is not the lamp:
Say "That's not something that plugs in.".
Before plugging the lamp when the lamp is carried:
say "(first dropping [the lamp])[command clarification break]";
try dropping the lamp.
Before plugging the lamp when the location is not the study:
say "There are no power outlets in [the location].";
stop the action.
The socket is part of the lamp. The socket is a container.
Instead of examining the socket, try examining the lamp.
Instead of inserting something into the socket:
if the noun is the lightbulb:
now the lightbulb is in the socket;
say "You screw the bulb into the lamp[if the lamp is operable and the lamp is switched on]. As you finish, the bulb flares to life[end if].";
if the lamp is plugged and the lamp is switched on:
now the lamp is lit;
otherwise:
say "That's not a lightbulb."
Instead of inserting something into the lamp, try inserting the noun into the socket.
The lightbulb is in the socket. Understand "bulb" and "light bulb" as the lightbulb. The description is "A typical 60-watt incandescent lightbulb[if the lamp is operable and the lamp is switched on], shining brightly[end if]."
Instead of taking the lightbulb when the lamp is operable and the lamp is switched on:
say "[The lightbulb] is too hot to touch."
After taking the lightbulb:
say "You unscrew [the lightbulb] from its socket in the lamp."
After deciding the scope of the player while in darkness:
if the lamp is enclosed by the location:
place the lamp in scope.
The wooden door is a door. It is south of the Study and north of the Featureless Void. It is lockable and locked. The initial appearance is "There is a[if the door is open]n open[otherwise] closed[end if] wooden door to [if the player is in the Study]the south[else]the north[end if].". The description is "A plain wooden door with few embellishments. The handle is round and has an antique-brass finish. There is a small keyhole in the plate beneath the handle.". Understand "handle", "plate", "keyhole", and "key hole" as the wooden door. The brass key unlocks the wooden door.
After opening the wooden door when the location is the Study:
say "You open [the wooden door]. Bright white light streams in from the other side.";
now the Study is lit.
After closing the wooden door when the location is the Study:
say "You close [the wooden door].";
now the Study is dark.
Test lamp with "take bulb / turn off lamp / take bulb / turn on lamp / put bulb in lamp / unplug lamp / turn off lamp / turn on lamp / plug in lamp".
Release along with an interpreter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment