Interactive Fiction Actions (Part 1)

Background

Porting to Actions on Google

Build the Action

engine = new ZVM();loadData(
'http://mirror.ifarchive.org/if-archive/games/zcode/LostPig.z8', (data) => {
self.sendInput({
code: 'load',
data: data
});
try {
engine.restart();
} catch (e) {
assistant.tell('Error: File format not supported.');
return;
}
engine.run();
});
step (response) {
const orders = engine.orders;
for (i = 0; i < orders.length; i++) {
let code = orders[i].code;
if (code === 'stream') {
...
} else if (code === 'read') {
...
order.response = response;
engine.inputEvent(order);
...
}
}
}
./gactions preview --invocation_name "voice adventures"
./gactions simulateUser TTS (CTRL-C to stop):
talk to voice adventures
Action: Sure, here's voice adventuresLost Pig. Grunk think that pig probably go this way. It hard to tell at night time, because moon not bright as sun. There forest to east and north. It even darker there, and Grunk hear lots of strange animal. West of Grunk, there big field with little stone wall. Farm back to south.User TTS (CTRL-C to stop):
inventory
Action: Grunk have: torch (on fire), pants (Grunk wearing them)

Retaining State

assistant.data.restore = this.data;
  1. Create a new instance of the interpreter using a cached copy of the game file.
  2. Tell the interpreter to restore the game state using the incoming session data.
  3. Pass the raw user text to the interpreter.
  4. Parse the interpreter response and pass it back in the action HTTP response using assistant.ask to get the next user input. In addition, the game state is saved and passed back with the HTTP response.

Next Steps

--

--

--

Former Google Assistant Developer Relations Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How the Angular Fire Library makes Firebase feel like Magic

React Native Lesson after 2 Years

JavaScript Error Handling — Throw and Try to Catch

Evolution of a Node.js API, Zoe.js — Workspace Setup

Webpack — All you need to know

7 JavaScript Design Patterns Every developer should knows.

Web3Js setup in ReactJs Project.

Lighthouse as a Service: Scan WebPages for Performance, SEO and Best Practices

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Leon Nicholls

Leon Nicholls

Former Google Assistant Developer Relations Engineer

More from Medium

Extent virtual storage in Ubuntu server

Payment Link Strapi plugin Part 1 — The server

OPENAPI: GO-Fiber Server Stack Generation

Setup an Apex/Root domain URL with Namecheap and Heroku