Fiction is a Three-Edged Sword

Fiction, interactive fiction and narrative

Undum “say” function

3 Comments

I’m working on tidying up the tool I’ve written for making Undum game-files from a simple text format.

While I get that sorted, I thought I’d publish the single most useful other Undum thing I’ve got, which is an extra function to avoid writing in HTML. Following I7’s lead, I’ve called it “say”, rather than the Undum default, which is “write”.

The code is available here, and you can copy and paste it into the undum.js file that forms part of the undum code package. It needs to go in the System prototype object, so just below the System.prototype.write definition will do.

At its most basic level, what the say function does is provide a way to print a string of text to the game without the need for any HTML tags around it. (The Undum default requires everything to be encased in valid HTML tags, which can get cumbersome.)

But on top of that, it lets you insert other features – most usefully links, but also italics, bold and images – in a simple, punctuation-based mark-up. I found this substantially sped up my ability to write Undum stories because all those “a href” tags were bogging me down and I was making a lot of typing errors with all the tags and angle brackets.

Here’s an example of the say function being used:

system.say(“What a -glorious- day! This *beats* the office![br]But you can’t stay here forever.”);

system.say(“You could choose to _go back to work_ [goback] or _bask in the sunshine a moment longer_ (bask).”;

The hyphens (-glorious-) will produce italicised text, and the asterisks boldface. The [br] tags produces a paragraph break. The _underscores_ denote links and the text in [square] or (curved) brackets the situations or actions these links point to.

There are a few more mark-ups, detailed in the comment at the start of the code. The only other one really worth mentioning is the “list” tag:

system.say(“[list]\

* Go north [gonorth]\

* Go south [gosouth]\

“);

which produces an Undum option-block of choices, automatically transient so they’ll disappear once one is clicked.

Here’s a link to a text-file with the say function in.

Next up will be the full perl script for converting a format like this:

thegardenintro

“Today is the perfect day for lounging and drinking lemonade. So long as there are no interruptions.”

* Lounge                  [lounge]

* Drink lemonade [lemonade]    { quality[lemonade_held] == true }

* Go to sleep           {[sleep]}

… into Undum-ready javascript.

Advertisements

Author: joningold

Jon Ingold is a writer and games designer from Cambridge, UK. He is co-founder of inkle, a company specialising in interactive narrative for mobile devices. He has written prose, plays, short films as well as interactive fiction, both in hypertext and parser-based systems. His short stories have appeared in Interzone magazine and his IF works have won competitions and awards.

3 thoughts on “Undum “say” function

  1. Just discovered you via Undum, and I have to say the stuff you are working on is great! I am going to try my hand at making and Undum game, and perhaps even look at how hard it might be to make a js version of your perl script…

    • Hey Andrew,

      Thanks for the comment! If you’d like to take a copy of my perl script to play with, I’ll happily send it over, with a few health warnings attached. The main thing holding me back from releasing it at the moment is that it requires some tweaks to the core undum javascript file to work, and as a perl script, I’m not sure how useful people will find it.

      I’ve got a daydream about a js front-end that looks a bit like a Google doc, where the author drag-drops their file in (or even types natively, with searching and checking and all that), and then the playable web-page opens below, or in the tab next door… But that might be a little bit pie-in-the-sky for now…

  2. I dont think that’s all that far off in terms of an idea. I’ve been looking for a IF type library to use for my own worlds, and wished it was based on javascript. I believe I’ve found it here 🙂

    I think once I figure out how you construct scenarios, etc I could work on a potential editor. Check out this js lib as a potential interface:
    http://jsplumb.org/yui3/demo.html

    I’ll check out your code this weekend if you send it to me (see my email addy) and perhaps adapt it for js. Having a “drag and drop” + live preview would be really nice. Plus, I’d be helping myself as well 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s