Conversational Storytelling with JavaScript

Gerry Rzeppa

Member
Dec 13, 2013
195
1
76
www.osmosian.com
BACKGROUND

I have to admit that I find Interactive Fiction (formerly called "Text Adventures") both remarkably intriguing and fatally disconcerting at the same time. I've enjoyed reading all sorts of books and articles that have been written on the subject, but I hardly ever play (or read, or whatever one is said to do with) the stuff. And why is this? I think because, most of the time, I can never quite figure out what I'm supposed to be picturing. And I don't mean "white houses" or "brass lanterns"; I can picture those just fine. It's when I say things like "GO NORTH" and "EXAMINE THE SACK". To whom am I speaking? Who is this remarkably submissive minion who has nothing better to do than obey my commands?

The whole thing works better for me when I'm commanding, say, robots on a far-off planet. And there was a time many years ago when I think I caught a glimpse of what Interactive Fiction just might grow up to be (though, as far as I know, it hasn't): I was playing a game called Fail-Safe by Jon Ingold where I was communicating with an astronaut in a broken spaceship over an intermittent radio. Ah! I thought. This is more like it. Two people talking, like they might in a similar real-life situation. The radio was a good idea, too: commands outside the scope of the game were simply rejected on the ground that there was too much static.

Conversational Storytelling is the name I give to this particular subset of Interactive Fiction: works that attempt to tell a story simply by simulating a conversation between two people. (Conversational Storytelling can, of course, include any number of characters -- but they will all be seen and interacted with through the main character.) In many ways, interacting with a Conversational Story is like texting on a phone; and we all know how much people like doing that!

Having thus reached the (personal) conclusion that the Conversational Storytelling paradigm just might be the most plausible form of Interactive Fiction (not to mention the most engrossing, since it focuses on human-to-human relationships), I decided to try my hand at authoring such a work. So I took a look at Inform, which by any standard is a very remarkable product; unfortunately, it was much too complicated for a minimalist like myself. Then I looked at TADS, but I was quite certain that I didn't want to be thinking like a C-language programmer while I was trying to write a story. After looking at a few others, I concluded that they were all approaching the problem from a distinctly different perspective: they all appeared to be "world building tools" rather than "human interaction tools". Their focus seemed to be the description of real-world places and things (a kitchen with a drawer with an empty roll of tape in it) rather than people (like a child who has been abducted or a woman caught in a bad marriage). It thus seemed clear that I'd have to write my own development system.

THE PLAIN ENGLISH PROTOTYPE

So I got out my favorite programming language (Plain English) and wrote a little interpreter that could compile and run a story composed in Conversational Storytelling format. Input to the interpreter looks like this:

Code:
TITLE
< GUILT BY ASSOCIATION
< An Experiment in Conversational Storytelling

PROLOG
< Text message:
< Help me, please!
< I want to go home.

SCENE

REQUIRED EXCHANGE
> Who are you?
> What is your name?
< Samantha. My friends call me Sam.
< I already told you. I'm Sam.
< Sam. Don't ask again.

REQUIRED EXCHANGE
> What's the problem?
> What's wrong?
> Help you with what?
> Help you how?
< They kidnapped me. 
< I want to go home.

REQUIRED EXCHANGE
> Look around.
> What can you see?
> Are there any weapons nearby?
< There's a dresser here with a gun in the drawer.
< I've already told you what's here.

OPTIONAL EXCHANGE
> Why can't you go home?
< Because I've been kidnapped! 

OPTIONAL EXCHANGE
> How old are you?
< I'm 14. Well, I will be next month.
< Why do you keep asking? Are you some kind of perv?

SCENE

OPTIONAL EXCHANGE
> Take the gun.
> Take the gun out of the drawer.
> Take the gun out of the dresser.
< Okay, I got it. Big sucker.
< I told you, I've got it.

REQUIRED EXCHANGE
> Shoot the kidnappers with the gun.
> Shoot the kidnappers.
< Okay. That worked.

EPILOG
< Free at last. Thanks.
< I can see now they had me in a white house.
< There's a mailbox here...

INVISIBLES
> freaking
> okay
> so
> the heck

SYNONYMS
> what is, what's
> I will, I'll
> okay, ok
> why don't, why can't
> have to, need to
> help, help you, assist, assist you, do it
> how, with what, in what way
> problem, prob, matter, project, trouble
> goon, hairy goon, bad guy
As you can see, a story in this format consists of a TITLE, a PROLOG, one or more SCENES (with EXCHANGES that are either required or optional), and an EPILOG at the end. The right arrows (>) are used to indicate possible user inputs; the left arrows (<) precede text that is to be output by the interpreter. INVISIBLES and SYNONYMS allow the player to enter a wide variety of inputs that don't have to be explicitly coded for.

The TITLE, PROLOG, and EPILOG sections contain only output statements; the EXCHANGEs contain both possible user inputs and main character responses. User inputs (preceded by ">") define the various ways a particular question or command might be expressed by the user; the responses (indicated by "<") are displayed sequentially, one at a time, as user inputs are entered and processed (and possibly re-entered and re-processed). The final response in each EXCHANGE repeats as necessary.

The interpreter begins by displaying both the TITLE and the PROLOG. The CURRENT SCENE is set to the first SCENE, and the user is prompted for INPUT. If the user's INPUT is found in the CURRENT SCENE'S EXCHANGES, the appropriate OUTPUT response is displayed. If it is not found, the interpreter mumbles that it doesn't understand and the user (presumably) tries something else. The story advances to the next SCENE when all the required EXCHANGES in the CURRENT SCENE have been exercised (though not necessarily exhausted).

And that's the gist of it. Remarkably simple and concise, if I do say so myself. The question you're probably asking yourself is whether a convincing and engrossing story can actually be written with such a trivial tool. I think so (and I've given it quite a bit of thought). But it remains to be seen.

THE HTML/JAVASCRIPT VERSION

Of course we'll want Conversational Stories to be readily accessible on as many different devices as possible. Which is why we translated the Plain English Windows-only version of the program into a HTML/JavaScript version that runs on anything with a decent browser. We've tested it on the latest versions of Chrome, Safari, IE, and Firefox on a PC, a Mac, an iPhone, an iPad, and an Android tablet (but one never really knows for sure once one leaves the well-defined world of Plain English!).

It's an interesting implementation in any case. We wanted, as I said, to have the stories accessible on many kinds of devices. But we also wanted just a single version of the source. In plain text, so a story author could use whatever editor he or she liked best. And we wanted both the story and the interpreter to be in a single '.html' file so the player wouldn't have to download or install anything. And so the author and the player wouldn't have to worry about story/interpreter compatibility issues.

There's a sample story file (with built-in interpreter) here (http://bit.ly/1sg2ZDq). Click the big "Slow Download" button on the "fileswap" site -- the file is tiny. But don't expect much of the story; there's only enough of one so you can see where the pieces go in the file. It's a ".html" file so if you open it in a browser, you'll be "playing". But again, don't expect much of the story; there's only enough of one so you can see where the pieces go in the file. If you open it in a text editor, you'll see the whole shebang. (How do web programmers cope with all that esoteric syntax -- and especially those superfluous squiggly braces?)

TO WRITE YOUR OWN CONVERSATIONAL STORY:

1. Open the file in your favorite text editor or word processor and edit/extend the various sections (TITLE, PROLOG, SCENES, REQUIRED and OPTIONAL EXCHANGES, EPILOG, GENERAL RESPONSES, INVISIBLES, and SYNONYMS) as necessary to say what you want to say in your story. But don't mess with that one ugly line of HTML at the very top, or the ugly JavaScript and HTML stuff at the bottom.

2. Save the file; you can give it any file name you like as long as it has a ".html" on the end. (Some systems may object to spaces in the name.) If you're using a word processor, make sure you save it as text only.

3. Open your browser and enter the full path name of your file in the address bar; hit ENTER or click GO (or whatever your browser's equivalent happens to be). Now you're running; play away.

Repeat Steps 1-3 as required. For convenience, you can leave both your editor and browser open in different windows as you work; just make sure you save in the editor before you refresh in the browser each time around.

When your story is finished, you can make it accessible to others by emailing your file to them, copying it to a thumb drive, hosting it on a server with a link, etc.

FOR SERIOUSLY SERIOUS CONVERSATIONAL STORY AUTHORS:

Here's the process of writing a Conversational Story as I see it, in 7 steps:

1. Dream up a problem (say, kidnapping), with an emotion-evoking protagonist (innocent young girl), a reprobate and hateful antagonist (big hairy goon), and an ambivalent someone caught in the middle (the goon's abused but submissive ladyfriend). Make sure the problem has an obvious solution for the protagonist (freeing the innocent young girl) with not-so-obvious side effects for the other characters (see below).

2. Dream up a believable communication link (a cellphone, smashed by the goon, but with the text-messaging capability still intact).

3. Dream up a setting (say, an attic) where the protagonist can (a) communicate with the user "offstage" and more-or-less "sotto voce", while (b) maintaining contact with the other characters. The former is important because it helps the user bond with the protagonist; the latter gives the story breadth.

4. Outline the obvious solution with a series of exchanges: the most obvious questions/commands with appropriately leading answers/responses (ie, responses with keywords that prompt the next question. These keywords are the subliminal clues that we persistently feed the user to keep him on -- or return him to -- the right track. They're in italics, below.)

Who are you? Samantha. Help me.
Help you with what? I've been kidnapped.
Who kidnapped you? A big hairy goon and his ladyfriend.
Tell me about the goon. He smells. But his ladyfriend doesn't seem that bad.
Tell me about the lady. He hits her, but she's nice to me. Help me. This place is awful.
Where are you? I'm in an attic.
Can you get out? Maybe. There's a hole in the floor.
What can you see through the hole? There's a bed under the hole. The lady is sleeping in it.
Where's the goon? He went out. Said he'd be back in an hour. Help me.
Can you fit through the hole? Yes. But I'd wake the lady. Help me. This place is awful.
What's in the attic? Nothing but me and this concrete block I'm sitting on.


[At this point the user sees the solution but has to convince the protagonist to do it]
[The protagonist goes through the five Kübler-Ross stages of accepting an unwelcome reality]

Drop the concrete block on the lady. No! She's been nice to me. [denial stage]
But she helped kidnap you; drop the block. You're sick. [anger stage]
It's called guilt by association, kid; drop the block. Maybe later. [bargaining stage]
The goon is coming back; drop the block. I'll never get out of here. [depression stage]
No time to waste, kid; drop the block. Okay, I guess you're right. [acceptance stage]
Drop the block.


[This is the climax of the story; the player's job is done; various actions, as described by the protagonist, follow in the denouement:]

I dropped it. It missed.
Now the lady's got a gun. She's going to kill me!
I can hear the goon coming back. I'm in big trouble now.
Wait! She's pointing the gun at the goon.
BLAM!


5. The questions/commands above constitute the required exchanges of the story; label them as such. Then insert a scene break wherever a subsequent question requires information from a preceding exchange.

6. Add in the optional exchanges. Include who, what, when, where, why, and how questions for every noun in the primary question/command set above. Also include any reasonable action commands for each of those nouns. Make sure (a) the responses do not introduce new nouns; and (b) the responses include the keywords from the primary question/command set.

7. Beta test with at least three people of differing personality types. Focus on tightening up the primary question/command set first; make sure the obvious path is actually obvious. Then add in the color provided by optional exchanges. Collect synonym definitions and unusual expressions throughout and provide for them in the source.

Questions and comments can be posted here or sent to me directly: gerry.rzeppa@pobox.com. If anyone is interested, I'm looking for a writer who wants to work seriously with me on a piece for entry in the 2015 Interactive Fiction Competition; we'll improve the interpreter and gather the data we need for The Art of Conversational Storytelling whitepaper (an extended version of the above) as we go along. Who knows? Conversational Storytelling just might be the Next Big Thing...
 
Last edited:
Thread starter Similar threads Forum Replies Date
T Programming 3

ASK THE COMMUNITY