.bat files - writing them as per the Z-machine Standards? Alternatives?

So I’m writing a game, in which I want to have a batch file by creating and writing to a batch file that was made by the game (which the player can play a mini-if piece from). This is Z-machine version 5, by the way.

Unfortunately, the only way to create this external file is, as per the Z-machine standards, is to save an array to the file, but if I’m correct this file is encoded in hexadecimal. I’m not sure if this is accepted.

Is there a file type that can run on most computer OSes and be coded in hex? I think coding another .Z5 file would be pushing it as those files have A LOT OF data and I just want something small.

Can you clarify what you mean by “batch file”? A normal Windows .BAT file filled with command-line instructions? (This will, naturally, only run on DOS or Windows.)

The z5 extended @save and @restore opcodes usually save the array in the same binary format in which it is stored in memory, not as hexadecimal values. In Inform 6 this means you would need to store the raw ASCII values in a byte array; in ZAP assembly you could define a .BYTE array with the data, or write the bytes into a region of dynamic memory with PUTB instructions and then save it with SAVE.

The main limitation of SAVE and RESTORE is that you must read or write the entire file in one go (there is no way to do random-access read/write on only part of an auxiliary file).

1 Like

Batch files and shell scripts are probably your best bet, but they’re far from universal. People playing on a phone or in a web browser, for example, won’t be able to execute arbitrary code you give them.


If your output “batch file” doesn’t need to access further files, could it be .html ?

The user would click on the HTML file and it would load into their default browser. There would be also JS. And It might even work on different OSes ?

1 Like

Could it just be a game-within-a-game - part of the zcode file itself? You could have a little dynamically generated section that looks and acts very differently to the main game, before returning to the main game when it’s finished.


I use ZAP (and ZIL), but whenever I try to open one of these auxiliary files, I open it with a hex editor:

…Though as you mention, it is encoded in bytes.

Well, that opens the question:

is there a more universal alternative to .bat files that can be written in bytes? (Or whatever that is, I’m not sure.)

Could be, but I really want the authentic feeling of closing the window, and seeing a new file and worriedly opening it, and it’s something interesting.

That’s certainly the wrong reaction to seeing a strange file on your computer.

Yes, you can output binary files or scripts this way. In general it is not possible to make it platform agnostic, which is kind of why the z-machine was created in the first place! That said, there are some interesting hacks that can be done, but they are advanced, tricky, and not 100% workable.

Saving a file without prompting and letting the user know you are doing it is bad form, and should be avoided.


Both Z-Machine and Glulx (and probably most other IF formats too) are quite restrictive in what they let storyfiles do. They generally can’t read or write arbitrary files, so that the storyfile can’t access private data, nor overwrite important files. Even within the same directory as the storyfile they’re restrictive, only writing savefiles, transcripts, or datafiles. You can’t change the file extension, so you can’t write any sort of scripting file. In order to do what you’re thinking of, you’d need to use a custom interpreter without these restrictions, but that means it wouldn’t work if players tried to use their normal interpreter, and many people do like to just download the savefile and do that. Of course it wouldn’t work online either.


Yeah, if I see a strange shell script appearing on my computer without warning, I’m absolutely not running it. That’s a good way to get ransomwared.


you mean you wouldn’t launch “funIF.bat”

1 Like

No, as in it’s kind of prompted it would happen (it has a very important link to the game, and it’s an endgame part).

1 Like

I’m just teasing. I like games that simulate interacting with computers.

1 Like

If the byte array consists of correct ASCII and named with a file extension that is associated with text (Windows), it will perform as a bat-file. This is a bat-file opened in a hex-editor:

As you can see there is no header that specify the file as, in this case, a text-file.

1 Like

It actually works! Now just to actually make the batch file…

A batch file will only work on Windows.

1 Like

One of the problems. Is there an alternative for all OSes, or worst case, the other computer types?

Sadly no.

Well, I say “sadly”, but a universal scripting language would be a universal malware target. Windows started out by saying “anything can run a batch file! It’s super convenient!” and then had to spend about twenty years putting in security restrictions around that.


Nope. Like I said before, needing something that can run on any platform was a driving force for creating the z-machine.

Even if such a thing existed, you’d be unable to set the executable bit needed for any *nix OS, Mac and linux in particular. Windows only works because it is brain-dead in this particular way.

Your best and only hope for running on any platform is an html file with embedded javascript…or another zcode file. :laughing:


Your best bet might be an HTML file with some JavaScript in it. Web browsers have a lot of sandboxing to prevent malicious HTML files from doing anything to the surrounding system, because you’re expected to (effectively) download and run them from all over the web.