In-App Payment in a Text Adventure with Alexa

My last blog post was about “walking” through a text adventure with Alexa and adding items from the text adventure to a shopping cart. People liked this idea, but they also wanted to “gamify” it by making it possible to buy items in the app to progress faster. Instead of spending time searching for a key, you can buy one.

Hacking the text adventure engine

The Inform text adventure engine wasn’t made for in-app handling. But it can read and write a file and check if a file exists. Therefore my Alexa skill fetches every buy command before it gets to the text adventure engine. Then adds the item to the shopping cart, creates an order (in YaaS), and then writes the order ID to a file. The next time when the user tries to unlock a door, the engine checks if a file with an order ID exists or the player has got the key in his inventory.

By the way, this logic is written in the Inform programming language like this:

As you can see, the Inform programming language is a “language based on principles of natural language” (see Wikipedia Inform) and they use Natural Language Programming, which is a type of Natural Language Processing (both use ‘NLP‘ as abbreviation).

Inform (version 7) has been around for more than 10 years and this is the kind of software where you just write a program like writing a book. So even non-programmers could write software. But, to be fair, as a programmer I’m already trained to write, think, and understand this:

This brings me to the question, after we’ve installed all these spying devices, will we also adapt our (daily) language to match these devices in a similar way to George Orwell’s Newspeak?

4 thoughts on “In-App Payment in a Text Adventure with Alexa

  1. Madhusudhanarao Jyothul says:

    That seems to be a good idea, what are the costs of the training it requires for the system and NLP involved for this evolution of automata.

    • Lars Gregori says:

      Thank you for your comment.
      There wasn’t training involved for this small demo. I’ve added all possible commands as Sample Utterances to the Alexa skill. This shows also the limitation of these devices and how we (as human beings) interact with them. In a context like a text adventure you can figure out the commands by your self. In something open it is on one side hard to figure out what’s possible and on the other side (at the backend) to understand it.
      So, for the NLP part for natural language processing I’ve filled up the Sample Utterances. The natural language programming for the text adventure is handle by Inform (which is freely available) and the text adventure engine which just runs the compiled byte code in the backend (on Node.js).

  2. Gangadhar Nittala says:

    This is a very interesting exercise Lars. Thank you for not only trying this out, but also, publishing the results for it.

    Just so that I am able to understand it better, the intent of doing this was to use voice commands (from Alexa) to not only play Zork using Alexa but to ‘gamify’ an ordering process. And to do that, you did the following

    1. Setup Alexa without a real Alexa device, but on your Macbook
    2. Setup the Alexa Skills for the verbs to be used in Zork
    3. Ran the Alexa Skill Server on CloudFoundry (this bit is not clear to me – more later in the comment)
    4. Then you start playing Zork via Alexa (Alexa on Macbook for the test)
    5. You modified the game to ‘add leaflet’ or ‘add golden egg’ to provide voice commands to an order management system
    6. These commands then would trigger an order creation in YaaS
    7. And then you further enhanced the game so that when the user has the golden key (in the game) only then can the user place the order – and to do this is where you stored the OrderId from YaaS in a file, and used the game to look for the file.
    7.1 If either the Order-Id file exists or the player has the golden-key, you ‘say’ click i.e. use the game to send a command to the Alexa Skill Server to actually place the order on the YaaS order micro-service

    Is the above an accurate sequence of steps of what you are trying to achieve? If not, can you please clarify the steps that are invalid. And if the above is accurate, then a few questions

    1. Did you modify this Inform source [] of Zork, build your personal version of Zork to run on Quexe.js to add the extra processing?
    2. You mentioned that the Alexa Skill Server fetches every buy command before it gets to the game – can you please explain a bit further on this. The ‘buy’ commands are coming from the game isn’t it? If so, the game is the one sending the ‘buy’ command to the Alexa server isn’t it? Can you please provide some more details
    3. Is it possible to publish the modified Zork Inform source, so that we can take a look at the order processing gamification (or you can email me if you can’t publish it)
    4. You mentioned that you ran the Alexa Skill Server on CloudFoundry – what does this mean? Isn’t the Alexa Skill Server already a ‘SaaS’ available to consumers? What does the CloudFoundry provide more?

    And finally, about the note around NLP, I don’t think this is NLP in the true sense, since the verbs are fixed in any IF. And you managed to find a very innovative voice input + modified game to gamify the functionality.

    A bit of background for those who are not very aware of the IF ecosystem
    1. Infocom developed the original Z-machine, which was a VM for text adventure games
    2. The original Infocom binaries are not available now, but the VM format was available for others to write interpretors
    3. One of the widely used one is the Inform programming system for IF, which generates its output in the Z-machine format or the Glulx virtual machine format
    4. Glulx provides a 32-bit address space as compared to the 16-bit address space of the Z-machine VM, thereby allowing larger ‘programs’ i.e. games to be run
    5. As mentioned above, the Inform IF system can generate either Z-machine or Glulx VM output (think of them as .class files)
    6. Quixe is a VM for the Glulx written completely in Javascript and using the browser DOM for rendering the game. The other VMs for Glulx are Glulxe, Git, Zag etc. More here –
    7. It is possible to run Quixe ‘headless’ i.e. without using a browser using Quixe.js – and by doing that one can send inputs to the game and play the game without requiring a textual entry-path i.e. a browser or a binary
    8. BTW, the game link of mentioned by Lars is running a .z5 file ported into Inform by Ethan Dicks [] running in the browser using parchment. Much like how Quixe can run the Glulx VM in Javascript, parchment can run the z-machine VM on a browser

    • Lars Gregori says:

      Thank you for your (long) comment which also clarifies some points. It took me a while to work through it 🙂

      The sequences you describe are correct. Step 7 is (as you mentioned) an enhancement. For this new version I’ve written my own text adventure with just two rooms: “in front of a house” and “in the house”. The main goal for this demo is to unlock the door by buying the key.

      About Question 1.
      For the first version I’ve used the Zork project from which isn’t available any more. But the story file contains only the house and forest which is fine for my first demo.

      About 2.
      This is the workflow:
      Voice –> Alexa –> Amazon –> call CloudFoundry instance with (Node.js) –> return Text –> Amazon –> Alexa –> Blah

      If the starts with ‘buy’, I call the REST APIs to create an order, write the file and skip the text adventure engine. If not, I send the to the text adventure engine (my quixe adaption) which handles this command and send back some text.

      Note: To accept the payment you have to say (loud and clear) a PIN number. This is also handle in the code and not in the text adventure.

      About 3.
      The ‘magic’ to redirect the buy command happens in the Alexa skill and the adjustments for the Text Adventure is the part I’ve blogged.

      About 4.
      We are using CloudFoundry, but the Node.js code should also run on AWS, GCP, Azure, and …

      About NLP
      You are right. In this case I’m adding every possible command as a Sample Utterances to the skill. I’ve also added “buy key” instead of “buy {item}”. Therefore the changes are very high that Alexa will recognize ‘key’. It could be more generic but my criticism is that we (the world) have stupid backends at the moment. They wouldn’t understand something like this: “Oh no, I couldn’t find the key. I tried it really really hard. Can you help me, pleeeeease?”
      In a human to human conversation you would ‘hear’ that the person is very interested to find the key and he/she would pay 1.49 instead of 0.79 for this key … and maybe 2.79 with a (virtual) jewelry on it.
      So, will we have 2027 this intelligence or have we adapted our language?

Leave a Reply

Your email address will not be published. Required fields are marked *