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).
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.
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.
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.
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:
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.
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.