How to embed Inform into other game?

I have a computer game that is kind of a simulation. It allows moving from here to there, with elements of trade and combat. The storyline is a bit shallow though.

Thus I thought of adding missions, and why not reuse a system which has 30+ years experience? So I am thinking of embedding Inform into my game but am not sure whether it is possible and if, what might be the best way.

Should I create my own compiler so it emits stuff that my game can understand? (there is some ECMAScript capability already integrated)

Should I write a custom GLULX VM that runs inside my game?

Should I try to integrate GLULX into the game and hope for the best?

Happy to listen to ideas, maybe someone has already done this?

1 Like

The new version of Inform can output C code instead of Z-machine or Glulx, which is probably easier to embed than an entire Glulx interpreter.

1 Like

I don’t have a full answer for you but here’s some bread crumbs:

  • If by Inform you mean the modern Inform 7 language, it has some ability to emit C code instead of Glulx and Z-Machine code. The stated goal is to enable Inform 7 programs to be embedded into other engines for purposes such as yours. This seems to be sparsely documented though – I’m not aware of any substantial documentation beyond the source code (a literate program).
  • Adding yet another backend is possible, see WIP: C# backend by rockwalrus Ā· Pull Request #155 Ā· ganelson/inform Ā· GitHub – but as you can see, it’s not exactly trivial, either.
  • If you mean Inform 6, which is indeed over 30 years old at this point… well, it’s definitely a smaller and simpler language. I’m not sure if adding an entirely new backend to the inform6 compiler would end up simpler than adding one to Inform 7, though. The latter is a larger program, but it’s also much more modular internally.
  • In any case, I wouldn’t advise someone who wants to make a game to get into the business of compiler hacking or writing a new Glulx (or other) VM. Both can be very fun projects if you’re so inclined, but they’re quite meaty for a side-quests and may keep you away from the main quest for a long time.
  • If you aim to embed Inform code by compiling it to Glulx and embedding an existing Glulx VM: you mention ECMAScript, so maybe you can reuse Quixe in some fashion. At minimum, you’ll probably have to rip out the GlkOte ā€œdisplay layerā€ and replace it with something more suited for your environment and use case.
  • Whatever you do, if you want to write reasonably normal Inform code that has its established world model and parser and turn sequence and so on, you’ll have to think about how to connect that to what’s happening in the rest of your game. How does the Inform code get invoked? How would it learn about the state of the surrounding game that it should react to? And how does its output get integrated into and affect the surrounding game?
2 Likes

Would like to answer your question in a pretty tangential way. Do you need a parser-based ā€œIF-engineā€ inside your game? For adding missions, it feels like something choice-based would fit a lot better. And there would be ink, which is made to be an IF-middleware for games.

Also, curious: Given your user name and the game description, are you talking about a fork of Oolite?

Seems I got caught. Indeed I am thinking of Oolite to host missions. How did you get that so fast?

If the new version can output C code that sounds interesting, yet a change in the story would require recompilation. Oolite allows to be extended with EcmaScript based extensions (called Oolite eXpansion Pack → OXP). Somehow I hoped embedding an Inform based adventure could go into such an OXP and would not require (much) change in the core system. Well, other solutions would also require changes, so what the heck. But having it in expansions would mean players, who often live up to creating their own expansions would be empowered in writing missions. Indeed, they already did but mission creation is quite heavy and thus rarely driven to completion.

To be flexible on what the mission is exactly about I rather think of embedding a VM than embedding Inform C output. Or is my assumption wrong?

Yes, communication is what the integration needs to solve. I’ve seen solely choice based adventures, and the riddles are a wee bit too easy to solve. Hence I’d prefer something like point and click as is known to many Lucasarts adventures - but basically it constructs simple text from the user’s clicks. Depending on what the Oolite interface could allow I’d have to go with point and click or direct text entry.

In what way would you rate choice based to be better suited? And can an engine designed for one also be (ab)used for the tother? Blue-eyed as I am, I believe a text-input engine can be used with choices but not the other way round?

So activities like moving around would require flying the ship to specific locations. When locations are reached (be it a solar system, a landing site or a distinct position in space, the adventure engine could be asked what to do. If text/graphics needs to be displayed, allow the player to interact. Whatever the result, it would be fed into the adventure engine to see what would happen next.
Could the player exit this kind of communication and just fly on? Likely - I’d still need to learn how that would work in detail.

Highlevel, consider moving from location to location to be the Oolite game, with trade and combat. On specific locations the adventure part can be triggered and take over.

How does that sound?

So, about the embedding side of things I don’t really know a lot, honestly. Just that Ink is designed to be embedded, and Inform (to my knowledge) not. So I just made the assumption, it would be easier with Ink. But then, they focus mostly on integrations into engines like Godot, Unreal, Unity. Here is, as example, some docs on how to do in unity, but there is also a javascript-port, since you mentioned ECMAScript.

To your question, how much can one shoehorn the one style of IF into the respective other - yes it works, in both directions, to some degree, with some clunkyness involved. I started once doing a parser-based thing in Ink, until I realized the combinatoric explosion of options presented to the player in certain situations. It is a fun experiment, but in the end it’s probably better to use the tool suited best.

One element that made me suggest something choice-based, would be dialogues, which are usually implemented in a choice-based manner (pick one of several answers). This is possible in Inform, the question comes up in this forum now and then, there is some plugin available to help with that, from what I read.

With the help of tracking variables, you should be able to track the current state of the mission in Ink, where each system could be a knot (passage), and depending on certain variables, you can change variables in ink, query those in the actual game and depending on the outcome, trigger events.

For example, in system A you have the offer to transport a mysterious passenger to system B. Once you arrive in system B, you could query if the player accepted the offer, and if so, greet him with a fleet of police ships.

Just remembered, this blog post gives maybe some practical insight on how it works (unity-based, again).

And when I talk about Ink all the time, no I don’t get paid for it :slight_smile: Twine is actually the noticable more popular and known contender, I just don’t know too much about the ability to embed it.

Overall, I do like your idea though, and I feel kinda tempted to dig out Oolite again. Last time I tried, my motivation (and ship) shattered a bit too often a few meters next to the station entrance.

2 Likes

I have had a look at twine and like it a lot. The graphical view of passages and their links allows to see loose ends directly. But then it is just choice-based. I could, in theory just use pure HTML or a wiki to create similar stories. Which means you’d have to work with variables to produce state machines for locations, NPCs or artifacts which are ā€˜invisible’ to the UI. As it generates dynamic HTML directly there is little hope to integrate it into Oolite.

I also had a look at ADRIFT and it pretty much hits the way I’d like to author a story. But then the interface is Windows-only, and embedding remains a myth.

Ink looks embeddable - proof for that is on Godot and Unity. But the complexity of the story seems again close to Twine.

Searching for yet another system I stumbled over Inform. Even if Inform 7 is pretty young, it was designed with the experience of the previous versions in mind. That’s why I asked whether that one could be integrated.

Maybe I should pick a low hanging fruit first and see how far I get. Which could mean to really follow your advice and take something that is embeddable. Whatever it can do will be much better than coding the missions in general purpose programming languages.

Thanks for the insight. :slight_smile:

BTW, if you ramp up your ship with a docking computer you can have that one take over all the docking maneuvers.

1 Like