Scripting stories

The past week has gone in putting some final touches on the story scripting engine in Pirates and Traders 2/Dwarf Kingdom. The original script engine of P&T was pretty poor; it has been improved on since then, but I’ve still not been quite happy with it for various reasons.

A couple of months ago, I did a new survey of the various interactive fiction/story script engines commonly used. I’ve done some research on various interactive fiction script engines in the past, but none of them have really suited my purposes. I need something that is extremely easy to write in (so that other people than me can write stuff if they want to), but which is also easy to parse. I also don’t want to be tied to a specific editor, because that is rarely a good idea. At the same time, unfortunately, I also need the scripting language to be pretty powerful – for a game like Pirates and Traders, for instance, I do a lot of calls into the core game engine to fetch stats, skills, even entire descriptions.

Inkle have a fantastic writing tool in their Inklewriter – probably the most beautiful interactive story scripting tool done yet; sadly, the scripts generated by their engine are not human readable (JSON). Most of the popular interactive fiction languages that I looked at had more in common with programming than writing; useful, given their use-cases, but not for me.

I spent a lot of time considering Choicescript. It’s popular (lots of games developed using it), well supported by the Choice of Games guys, and contains almost everything that I need. Unfortunately, they went for an indentation-based syntax. I wish they hadn’t. Indentation syntax isn’t easy for people to get used to, and invisible markup (e.g., the difference between space and tab) is simply an accident waiting to happen – especially in the hands of someone who isn’t used to programming. It makes having a great text editor pretty much a requirement for being productive – and most people don’t. Despite the many good things about it, I eventually decided to drop the idea of using the Choicescript syntax.

mobile_story

Cloak of Darkness

At this point, I’ve settled on a Markdown-based syntax. I fell across one such syntax, called Ficdown, during my research and was struck by how similar the structures were to the non-Markdown compatible syntax I was already doing. After a little bit of work, I’ve developed a syntax for the story engine inspired by this which creates readable text in a WYSIWYG Markdown editor, while retaining all the flexibility I need.

Implementing the new syntax was pretty easy, so it’s already functional. I did a small writeup on how it looks like on the future Pirates 2 wiki. Hopefully, it is also pretty easy to use for non-programming people. The idea is to have it so simple that anyone who wants to, can write their own small adventures/quests for Pirates and Traders, and have them loaded into your game where you can play them (the same as the existing stories). The documentation is not complete yet, but the core elements are there. I’ve been putting the final touches on the implementation this week, and hope to start (re)writing some of the encounters and quests for the game soon.

I also experimented a bit with creating a stand-alone story viewer for the Story Script (see the image on the left); as I thought this might perhaps be useful for modders in future. It’s very plain, but works well – as it should, of course (it’s 99% the same code as I have in Pirates and Traders – I pretty much just stripped out the fancy UI).

At the moment, I’m actually considering whether to publish the story viewer as a free stand-alone app. Feels like it could be quite fun to give people the possibility to write their own CYOA games using something as basically simple as Markdown. On the other hand, I’m not really sure the interactive fiction community really needs yet another scripting language/viewer. At the moment, I’m just planning to fool around with it a bit, continue writing stuff for P&T, post a little bit around, and see if there is any interest. If it’s the sort of thing you’re interested in, feel free to post a comment or send me an e-mail.

In the mean-time, I need to put the last touches on the story engine, and adding the final hooks into the role-playing module.