Remember text adventures, eh? They were pretty nifty!
"You are in a maze of twisty little passages, all alike"
"You have been eaten by a Grue. A dwarf starts singing about gold"
Smashing! Just like the pictures are better on the radio, so the graphics are immeasurably superior when they're in your head. Don't get me wrong, I love the 5.1 surround sound snarl of a rabid beast rendered in 1080p - but nothing is quite as good as using your imagination.
Text Adventures - or, more properly, Interactive Fiction - is enjoying a mini-renaissance at the moment. There are emulators for smart phones, computers, and consoles.
But for SMS? None that I could find. Think about it; SMS is close to the perfect medium for Interactive Fiction. Your commands are concise enough to fit into a single message, you don't have to worry about the speed of your response, everything is text based.
So, I present to you, Zork via SMS (with a little help from Twilio).
Although superficially a simple project, there are a few gotchas along the way. This documentation is mostly for me - but may be of use to you :-)
Let's start at the end.... Using Twilio you can send an SMS to a phone number, that is then POSTed to a webserver of your choice.
Twilio will send an SMS back if it receives a response such as
< ?xml version="1.0" encoding="UTF-8"?>
<sms>You are in an open field west of a big white house with a boarded
There is a small mailbox here.
Easy enough. (NB the free account prepends your messages with a trial message. Once you pay, that goes away.)
So, how do we get a text adventure like Zork running server side? There are plenty of client side emulators out there - but I only found one which was purely server side.
THCnet have a PHP interpreter for Zork. It's slightly cludgy - but it works. I'm checking to see if I can distribute it on GitHub.
The game library "dtextc.dat" must be installed in "/usr/games/lib/". The source code is available if you want to recompile it and place it somewhere more accessible.
A MySQL database needs to be created to keep track of users and sessions.
A temporary directory (which must be readable and writeable) will also be needed to store the state of play for each session. I've used "tmp/404/" but you can alter config.php to point wherever is convenient. You will also need to adjust index.php and functions.php with the new location.
Finally, the executable "zork" must be runable.
That's pretty much it.
When a user (or, in this case, Twilio) first makes a request to the URL, we check to see if they already have a session cookie.
If they don't, create one, and start the game by returning the opening text.
For every subsequent connection, we check the state of the game based on their cookie, then apply the body of their SMS to the game engine. Whatever Zork spits out, we return as an SMS.
By default, Twilio kills unused sessions after 4 hours, and all cookies will be lost.
It strikes me that the various forms of text adventures are excellent as a sort of mini-IVR. A nice little finite-state-machine which can quite happily run for years. Services like Frontline SMS are great for information sharing, but they're really not designed for this sort of work.
Could we use interactive fiction in places where SMS is cheap but other forms of entertainment are expensive? Could IF be used to augment existing media events? SMS is lowest common denominator - even iPhones can use it.
But, for now, all I have to worry about is someone texting me "Go west'); DROP TABLE ..." ;-)