Inform Embedded within Twine

I asked ChatGPT whether there is a way to embed a parser-based game (such as something written in Inform) into a Twine user interface, thereby creating a hybrid system that has the beautiful look and feel of Twine but also an underlying world model and the possibility of open-ended user commands via a command prompt.

I got a lot of fascinating information, which I have yet to go through … but it’s known that ChatGPT and other AI systems sometimes give incorrect information (or simply make stuff up). So my question is, are there a few Twine games that have actually done this? If so, what are they and who are the authors?

From my experience as a Twine/SugarCube sandbox game dev, ChatGPT/Claude has a terrible understanding of Twine, and especially SugarCube.

I suppose that it would be technically possible to do - e.g. create a parser system in good ol’ JavaScript and load it into Twine like a normal library, or just gut Twine from everything except the frontend and replace the backend with whatever you’d like, making some e.g. RestAPI between the two - but I think it’s just better to create a frontend from scratch within the parser library/language itself. Saves you a lot of headache.

As for any examples of this, I don’t think I’ve ever encountered such a mix.
Twine + Inform sounds quite exotic :smiley:

3 Likes

I expect you’re right about that. I certainly wouldn’t want to try to create a whole parser and world model from scratch in JavaScript. Life is too short.

I did manage to track down one game (DetectiveLand, the 2016 Comp winner) that appears to be running Inform inside of Twine, but possibly it was programmed in some other manner.

1 Like

Hand Me Down combines TADS and Twine, though less intimately than what’s being proposed here.

4 Likes

From the description, that appears to be an alternation between the two platforms – not unlike a flight from New York to Los Angeles with connecting flights in St. Louis and Albuquerque. Thanks for the suggestion, though. I’m learning a lot about what people are doing.

Since Sharpee is built in Typescript, this is entirely possible. Interesting idea.

Sharpee’s engine is completely UI-agnostic — the parser, world model, and action system are all separated from rendering. The same core API powers a CLI, a browser client, and a React-based runner (Zifmia). A Twine integration would just be another consumer of that API. The basic surface looks like this:

const world = new WorldModel();                                                                                      
const engine = new GameEngine({ world, player, parser, language });                           

engine.setStory(story);
engine.start();                                                                                                       

const result = await engine.executeTurn("take lamp");                                                    

// result.blocks → structured text output
// result.events → semantic events (item moved, door opened, etc.)
// result.success → boolean


There are a few ways a Twine author could leverage this, depending on how deep they want to go.

World Model as a State Engine (No Parser)

The most natural fit for Twine authors would be using just Sharpee’s WorldModel as a state management layer behind your passages. No command line, no parser — Twine links map to Sharpee actions directly.

This gives you spatial containment (items in rooms, items in containers), traits (locked/unlocked, open/closed, light sources, wearables), inventory management, and entity relationships — all without reinventing state tracking in SugarCube variables. The world model becomes a smart state machine behind the hypertext.

Hybrid: Passages + Parser

With SugarCube, you could have narrative passages handle story beats and choices, then drop into a parser-powered exploration mode for certain sections. Twine handles the narrative flow; Sharpee handles spatial reasoning, inventory, and object interaction. Players click links for the story, type commands when they want to explore freely.

This is compelling for authors who want exploration sections — “wander the dungeon freely, then return to the narrative” — without building the entire game as parser IF.

What Sharpee’s World Model Gives You for Free

The real value for a Twine author isn’t necessarily the parser — it’s the world model:

- Spatial relationships — rooms, connections, containment (items in boxes, boxes on tables)

  • Traits — openable, lockable, switchable, wearable, edible, light-source, etc.
  • Inventory and portability — items are portable by default, with trait-based blocking - Scope and perception — what can the player see, reach, or interact with right now?
  • Semantic events — the engine emits events like item.taken, door.opened, player.moved that Twine could react to for triggering passage transitions
  • Save/restore — world state serialization is built in

All of this exists today but is packaged for parser-based stories. A lightweight library bundle for embedding in other tools (Twine, Ink, custom web apps) doesn’t exist yet, but the architecture supports it cleanly. It’s something I’m curious about, but would leave it to others to explore.

Detectiveland used the author’s own Versificator engine. I don’t think it makes any use of Inform or Twine.

3 Likes

If what you want from Twine is primarily the fact that it looks pretty, rather than anything to do with its interaction model, then I feel like it would make more sense to look into combining Inform with something specifically designed to make pretty-looking interfaces, like some sort of nice CSS framework or something.

As I understand it, nice-looking Twine games look that way because the creator made good use of CSS and maybe some JS, not because of Twine itself. And you could apply those exact same CSS/JS skills to making any of the existing web-based parser interfaces look good as well. I think people just kinda don’t, for cultural reasons more than anything.

6 Likes

Even Some More Tales from Castle Balderstone uses a Twine story to narrate the meta-narrative while the interior narratives are a series of Inform 7 games, I think running in Vorple for Web interface styling.

2 Likes

There is one thing I think SugarCube makes easier than it would be working totally from scratch, which is having different style settings (like light mode vs. dark mode or changing the font). Otherwise, yeah, it’s all about knowing CSS and maybe a little JS, and given the amount of time I spend playing whack-a-mole with the default Twine stylesheet it might be more a hindrance than a help, tbh. (It will “helpfully” fill in any gaps you happen to leave, some of which are incredibly granular—“okay, you defined what the background color of this text box should be when not selected and on hover and on click but not while the player is actively typing so hello, default Twine CSS time!”)

Edit: And you actually do still need to know a little JS to take advantage of the settings API anyway, just less than you would need to construct it yourself.

2 Likes

whoami from last year’s Comp embedded a very good Inform imitation into a slickly-presented Twine game, so that’s probably a good proof of concept - I don’t know exactly how it was done though!

2 Likes

TADS 3 and Twine, and all available via HTML, but I couldn’t get the handoff to be reliably smooth.

1 Like

A lot of CSS styling and clever JS, to my understanding :slight_smile:

Yeah, whoami is implementing its own whole parser, much like people did in the BASIC days. Split the user’s input into words, match the first one against a verbs table, then hand off the command to the passage that implements that verb. So lots of stuff like

ACT_EXAMINAR
  • Take the last word in the command (ignoring all others)
  • See if it’s an object we know about
  • Show the object’s description, or “I cannot see that here”
  • Match it against a bunch of possibilities (if we examine the palm trees and there wasn’t already a coconut on the beach, put one there, etc.)
  • And some of this code is handled by (duplicated by) the objects, so the palm trees object also checks if there’s no coconut on the beach and modifies its description to include “at the foot of one of them I discover a coconut.”
<<set _arg = $command.args[$command.args.length-1] >>
<<set _obj = parser.parseObj(_arg, $state) >>
<<if _obj>>
	<<set $log = $log + _obj.desc($state) +"\n" >>
<<else>>
	<<set $log += "I cannot see that here.\n" >>
<</if>>
<<if _obj.t[0] == "palm" && not $state.items["coconut"] && $state.location == "beach" >>
	<<set $state.items["coconut"] = "beach" >>
<</if>>
<<if _obj.t[0] == "seabed" && not $state.items["coin"] && $state.location == "seabed" >>
	<<set $state.items["coin"] = "seabed" >>
<</if>>
<<if _obj.t[0] == "sea" && not $state.items["fish"] && $state.location == "sea" >>
	<<set $state.items["fish"] = "sea" >>
<</if>>
<<goto Input>>

Not at all the same as writing in Inform and having some help creating a fancier interface.

I wish Vorple went a lot farther in being easy to use: I was poking around with it a few weeks ago and the documentation is out of date in some crucial places (like many of the intro examples). And also it feels like a bunch of disconnected pieces built on top of the basic “here’s an Inform command to run some JavaScript” rather than something that’s easy for the basics and reasonable to extend to your needs.

Not that that’s an easy kind of tool to design: I think that’s very much what Vorple is trying to be, and as I said in the other thread, I think interface customization in Twine is a lot more work than people make it seem. But at least in the case of Twine there are lots of tutorials and examples, and things like the Twine Grimoire, whereas Vorple has kinda languished in obscurity…

2 Likes

It’s not parser but I did previously manage to get Harlowe and Decker to communicate within the same project. The Decker deck is embedded within one of the Twine passages, and then I just used each engine’s respective functions for Doing A JavaScript to issue a command to the other side. I didn’t have anything more interesting to use it for in that project than just having a button in Decker send you to a different Twine passage, so it’s more of a proof-of-concept. If there’s a way to send JavaScript commands from an embedded Inform game then I’m sure you can do something with it (even if the developers would rather you didn’t). But the level of integration described in the OP sounds more like it would warrant its own whole engine.

3 Likes

Good point. Twine in general is more actively supported with tutorials than Inform, and tutorials for Vorple … I’ll have to do a search to see if there’s anything. The Advanced Topics pages on the vorple-if website do give a lot of specifics that you won’t find if you’re just looking at the Vorple Extensions, so there’s that. But tutorials can only come from knowledgeable users, and as far as I can see, the user community for Inform is no more than 1% of the size of the user community for Twine. I may end up having to write the tutorials myself.

The intent of the parser section in whoami was exactly what @Jim_Aikin stated, having a parser interface that interacts with the Twine objects and provides a more open-ended gameplay (or the illusion of it at least).

The integration is pretty conservative: I stuck to the old school adventure game conventions and made a standalone section that simply returns a value out of four possibilities. But I believe the system could also support richer forms of hybrid UI.

4 Likes

Sure, it’d be possible, with enough effort. The obvious choice of architecture would be to just ape @Dannii’s Parchment

RemGlk is a Glk implementation not intended for direct use by people: its input and output are JSON. You compile a terp with it when you want to run a game as a back-end, and have some separate front-end intermediate between it and the user.

Emglken uses Emscripten to compile RemGlk-rs (Dannii’s port of RemGlk to Rust) along with your choice of Git or Glulxe to Javascript or Wasm. That terp is used to run some particular game; AsyncGlk presents and operates the UI and talks back and forth to the terp.

So “all you’d have to do” would be to write Javascript to interoperate between the back-end terp and Twine. This new thing would replace the AsyncGlk layer of the stack above, and Twine would be yet another layer on top of it. You’d have to make some decisions about little things like how saving/restoring the game would work.

Some other things that would probably be of roughly comparable difficulty:

  1. Ditching Inform and implementing as much world model as you cared about for use with Twine.
  2. Ditching Twine and replacing AsyncGlk with some original interface that would talk to an Inform back-end.

(As an aside, I think the degree to which Parchment / IPlayIF.com is a technical tour-de-force is underappreciated, 'cause most people don’t know how hard the problems are and fewer know how elegant Dannii’s solutions are. Kudos to Dannii.)

6 Likes

Ah, well. I just want to write a couple of games. I’ll have to wait for someone else to build the infrastructure. I was hoping Vorple would provide that, but it doesn’t.

I’m curious if you missed my post about Sharpee (Typescript parser engine) or did you just ignore it for some other reason. (https://sharpee.net).