Tuesday, September 22, 2009

Inform 7: Code-text

Here's the link to Inform 7, the interactive fiction authoring software I mentioned in our last meeting. I would recommend poking around with Inform to anyone looking to get a sense of how programming works.

Here's a snippet of actual Inform code (from an IF project I wrote last year):

Getting Groggy is a scene.

Getting Groggy begins when the player is on the bed for the fourth turn. Getting Groggy ends when the player is on the bed for the tenth turn.

When Getting Groggy begins:
say "[if the player is unenlightened]You're getting groggy. The drugs are making you feel like you're being buried in sand.[end if]".

When Getting Groggy ends:
say "[if the player is unenlightened]As much as you try to resist their effects, the drugs finally overwhelm you.[end if]";
if the player is unenlightened, try going to sleep.

Sleep Study Room is a room. "[if unvisited]YOU'RE NOT SURE WHY YOU DID THIS. You told your friends it was the eight grand the STIFLE foundation was offering as remuneration, but now, as the drugs flood into your system, something about that explanation doesn't ring true. Maybe it was what Jean said on the day you broke up, that you'd had so much trouble facing things that you'd put off dealing with the problems that might have saved your relationship, or if not that, at least ended it sooner, before the damage was done. [paragraph break]So maybe that was why you came here. To prove something to yourself. But if it was your courage you wanted to test, why not go skydiving or sign up for that humanitarian program you heard about, the refugee camp thing, the one where a quarter of the volunteers ended up quitting after less than a month? Or even better, why not just call Jean? [paragraph break]You can find no answers to these existential questions, no escape from the recursivity of your overanalytical and hypervigilant mind. But perhaps this 'treatment,' whatever it is, is just what you need to break the impasse. After all, the doctor said it was supposed to be a kind of therapy. 'Electrostatic dream therapy,' he called it. 'If this round of tests works out the way we think it will, it's going to revolutionize psychiatry,' he'd told you when you called about the Craigslist ad. So maybe you weren't being careless at all, signing up to be a guinea pig for this thing. Maybe this was your destiny, your way out of a lifetime of impossible-to-pin-down dysfunction. The thought gives you strength.[paragraph break][end if]The sleep study room is a rather bland hospital room with a single padded door to the south. An EEG machine sits in the corner next to the bed. A bundle of wires leads down from the bed and through a hole in the wall. There's a mirror on the east wall that you suspect is actually a window.[if unvisited][paragraph break]This is getting creepy. Maybe this was all a mistake.[end if]".

The bed is in the sleep study room. It is fixed in place and scenery. The description of the bed is "It's a typical hospital bed. Room enough for one." The player is on the bed.

The player wears an EEG cap. The description of the EEG cap is "[if the player wears the eeg cap]You examine the cap by looking at your reflection in the mirror. [end if]Hundreds of tiny wires are attached to a matrix of electrodes embedded in the cap. The wires collect into a bundle which is attached to the EEG machine."

In the sleep study room is a mirror. The mirror is fixed in place and scenery. The description of the mirror is "[if the player is wearing the eeg cap]You look at yourself in the mirror. The tangle of wires coming off your EEG cap makes you look like a futuristic Medusa.[otherwise]The mirror dimly reflects your image. If you squint, you can barely make out the outlines of a small room on the other side of the glass.[end if]".

Your reflection is in the mirror. The description of the reflection is "[if the player is wearing the eeg cap]The tangle of wires coming off your EEG cap makes you look like a futuristic Medusa.[otherwise]The mirror dimly reflects your image.[end if][if the player is enlightened][paragraph break]It strikes you that you look older somehow... Where did all those gray hairs come from? Maybe it's true what they say about nightmares.[end if]".

The EEG machine is in the sleep study room. It is fixed in place and scenery. The description of the EEG machine is "[one of]The EEG machine tracks your brain's alpha waves. You notice that it spikes whenever you think about Jean.[or]A standard-issue EEG machine. The more anxious you get, the more it responds.[or]The logo on the EEG machine indicates that it is manufactured by Meardrouy, Inc.[or]You see nothing else remarkable about the EEG machine.[or]The same old EEG machine, exactly as it always was.[stopping]".

The sleep technician is a woman in the sleep study room. The description of the sleep technician is "[one of]The sleep technician, an attractive woman in her late 20s, takes notes as she monitors the EEG and triple-checks the wires attached to your head.[or]The sleep technician smiles as she notices you looking at her, then resumes her work.[or]There's not much else to notice about the sleep technician.[stopping]".

Understand "get out of bed" or "get up" or "leave bed" as GettingUp.

GettingUp is an action applying to nothing.

Carry out GettingUp:
try getting off the bed.

Understand "go to sleep" or "sleep" or "fall asleep" or "relax" as going to sleep.

Instead of sleeping when the player is on the bed:
try going to sleep.

Going to sleep is an action applying to nothing.

After asking about Jean the sleep technician:
say "[one of]She presses a button on the EEG unit and writes down another note.[or][stopping]".

After asking the sleep technician about something:
say "The sleep tech [one of]smiles softly[or]clears her throat[or]brushes back her hair[or]sighs[or]scrawls down another note[or]makes an adjustment to your EEG cap[or]bats her eyes[in random order] and [one of]asks, 'Are you feeling the drugs now?'[or]says, 'That's something you'll have to ask the doctor.'[or]says, 'Now's not the time for talking.'[or]wistfully wonders aloud: 'Why do I do this job?'[or]says nothing.[in random order]".

Check going to sleep:
if the player is not on the bed, say "You try to sleep, but you can't. Maybe that's because you're already slumbering." instead;
if the player carries a totem, say "The drugs must have worn off. You feel much too alert to fall back asleep." instead.

Carry out going to sleep:
say "You drift off to the near-inaudible whirr of the EEG machine. As your eyes flicker shut, you see the sleep technician bending over you, a quizzical, almost bemused expression forming on her face...[paragraph break]";
move the player to Origin Point;
remove the EEG cap from play;
now the player carries the flashlight;
remove the sleep technician from play;
now the time of day is 4:00 AM.


Instead of getting off the bed when the player is unenlightened:
if the player does not carry a totem, say "[one of]The sleep study technician gently pushes you back onto the bed.[paragraph break]'If you left now, you'd just pass out somewhere outside. Don't fight the medication,' she says. 'Just relax.'[or]You try to get up, but the drugs are kicking in ever more strongly now. You can barely lift your head, let alone your entire body.[or]You can't.[or]The nurse smiles quizzically. 'Just go to sleep now. It will all be over soon.'[or]You muster up a second wind, despite the increasing paralysis caused by the drugs. You manage to get up onto your elbows, but that's as far as you can go.[cycling]".

Instead of getting off the bed for the sixth time:
say "You expend your last bit of energy trying once again to get out of bed. But the drugs have worked their magic, and you are helpless to resist them.[paragraph break]";
try going to sleep.

A person can be strapped down or free. A person is usually free.

Instead of taking off the EEG cap:
if the player does not carry a totem,
say "As you groggily try to remove your EEG cap, the sleep technician presses a button on a pager-like device she carries in her pocket. Moments later, two burly orderlies enter the room and strap you down.[paragraph break]The sleep technician shakes her head and smiles at you as the orderlies depart. 'Don't be alarmed. Sometimes the drugs make you have paranoid thoughts. It will be better this way,' she says. 'Now just relax...'";
now the player is strapped down.

Instead of taking off the EEG cap when the player is strapped down:
say "Your arms are now strapped firmly to the bed, making it impossible for you to reach up and remove the EEG cap.".

Instead of getting off the bed when the player is strapped down:
say "[one of]Unfortunately, you are now strapped to the bed and can't move at all.[or]Not happening.[or]The straps are too tight for you to move.[or]You can't.[stopping]".

The sleep technician carries a clipboard, a pen, and a pager.

The padded door is a door. The padded door is south of the sleep study room and north of the Purple Hallway.

Instead of opening the padded door when the player is on the bed:
say "You need to get out of bed first."

The Purple Hallway is a room. The description of the Purple Hallway is "The hallway south of the sleep study room glows with purple luminescence. It is very unusual for a hospital hallway, and stretches for what seems like a hundred yards. At the north end is a heavy steel door. [if unvisited]For the life of you, you can't remember coming down this hallway when you arrived. Indeed, you can't remember much about what happened before you got here. You wonder if you drove or took the bus. If you drove, you're in trouble, because you can't remember where you parked.[paragraph break]A familiar person stands near the door at the far end of the hallway.[end if]"

The steel door is a door. The steel door is south of the Purple Hallway and north of the Gelatin Orb.

Instead of opening the steel door:
say "As you open the door, your mind reels. Suddenly, you find yourself propelled through what feels like a thick gelatinous goo. Your vision blurs. Something SNAPS--";
move the player to the Crystal Cavern.

No comments:

Post a Comment