I want to create a windows console app retro syle text adventure and am wondering if it is possible to do this using Inform 7. Does Inform 7 compile to an executable file on windows that is able to create a console app?
I come from a C# programming world - yes, I know this can be done in c#!
However, the idea of using IF7 to do this appeals to me, if it can then be compiled into an .exe file to run as a console app.
Does anyone on this site have experience of this route? Or, know if this is even possible?
From the brief experimentation I have done so far, it appears that IF7 only seems to compile to Glulx and other obscure formats (at least obscure to me). I have not managed to discover a method to date that will allow me to accomplish the aforementioned goal.
Any pointers or help gratefully received.
Thanks for taking the time to read this noob post.
I don’t believe it’s possible to do this using the official Inform 7 IDE. However, if I understand correctly, the latest version of Inform (10.1, or even current master) has command-line tools that can compile an Inform 7 story file down to C code, which you could then compile into a conventional exe file. I don’t know much about how this works, however.
The other option would be to just distribute the Glulx executable (possibly a slightly modified one) as your game, and the “story” file is essentially a “data” file distributed with the game. Basically, think of it as a version of the interpreter that only runs that one story file.
Yeah, Inform by default compiles to platform-independent bytecode for a virtual machine, either the Z-machine or Glulx. A platform-specific interpreter then executes this bytecode on whatever platform you want, whether that’s Windows, Linux, a web browser, or a Commodore 64.
This means there are two ways to get a console app.
One is to bundle the bytecode with an interpreter for the appropriate platform. There are several that can handle I/O through the Windows console, so just pick your favorite (smallest, best output, most permissive license, etc) and write a little wrapper that launches the interpreter with your specific bytecode file.
The other is an experimental new feature in Inform, which can (as of the latest version) also output C code instead of the virtual machine bytecode. The resulting code is an absolute mess, and as far as I know this has never really been used in practice—the point isn’t to make standalone console apps, it’s to integrate Inform’s output with an engine like Unity—but it can be done.
I recommend the first, personally. It also means that people who aren’t running Windows can extricate the bytecode file and run it on their own favorite interpreters instead.
I tried the C target when I came out. Has it been updated since then? It did work, but the code was huge. On a good size game, the C output crashed my compiler. I made some hacks to inform10 to improve the C output and finally got a game to compile to binary.
I’ve been hoping to see an update in that direction.
I’m not sure; I haven’t tried it beyond the standard test suite for the compiler. But I don’t think much work has been done on optimizing it; it’s still a proof-of-concept more than something really usable.
I don’t know Inform 7 and how it works, but for example ADL and AdvSys interpreter works in a console. The interpreter uses standard output to print messages and standard input to get commands. So it can be just run from Shell giving the compiled story-file.
If there existed Inform 7 interpreter that works this way, it could be possible.
I only played Inform 6 games so far, using the Gargoyle interpreter that works in own environment, similar to console.
Thank you to all of you for taking the time out to respond to my question.
It sounds like I might have to implement using a different route.
I can understand why the C code generated is a complete mess! A very difficult task to try and achieve a good quality compilation, and no small task to implement.
I’m not a Windows person and fear I may not even understand what you mean by “a console app” in this context. But if you compile I7 to C and then compile that C, you get a stand-alone executable that should work on anything that understands stdio and stdout streams. I’d expect it to work in, say, Cygwin.
When the compiler’s target is C, the code it creates uses the Glk API for I/O (same as it does when compiling to Glulx). By default, it embeds MiniGlk, its own highly minimal implementation. By design, you’re supposed to be able to replace it with your own Glk implementation… but as Daniel notes above, if anyone has done this, they haven’t mentioned it here.
Inform’s C target is very much an early work in progress, so I’d leave that alone for now. A much simpler approach would be to just build a Glulx interpreter as a Windows console application: if you know how to build Windows C applications with Visual Studio, it isn’t difficult to build Glulxe linked with CheapGlk as a Windows console executable. With that done you can run a Glulx game in the Windows console with a command like
glulxe MyGame.gblorb
You could then even modify Glulxe to load a fixed game file, so you didn’t need to specify the game file on the command line.