Inspired by Drew, I’m making a thread. Can inform know if a meta command has taken place and do something about it? Like, disallow saving in a certain room, or move an item into the room if you saved there….
Sure!
The one trick to remember is that “before”, “instead of”, and “after” don’t run for actions out of world (which saving the game is). But “check” and “carry out” do:
Check saving the game:
say "You saved the game in [location].".
Or:
Check saving the game in a haunted room:
say "You can't save the game when there are ghosts around." instead.
Checking for a successful save is a bit tricky, because “report saving the game” also runs when you restore a game (because you restored to a point in the middle of the saving action). But if you want to do that, there are hacks involving responses that make it possible.
Thanks, it really is that simple huh? CAn it read the name of the save file?
Not by default. On Glulx it can be made possible with certain interpreters but not others. On Z-machine it’s not possible at all.
You could keep track of where the player saves along with some other identifying info (using the advice above), but to do something fancy like tracking after restoring a different file (ie, player saves in room a, then saves in room b, then restores back to room b), it would take some wrangling
But that wouldn’t have to do with the save filename specifically, if that’s the goal
Not the goal, fortunately. Honestly, just thinking of some cheeky langauge if the player saves at a certain place, and maybe some inventory shenanigans, but my inner Kojima was wondering about file names and the like….
Inform (or really the underlying VMs it’s compiling to) deliberately gives authors very little access to the file system, to make sure games can’t steal or wreck players’ unrelated files.
Could it…hmm, “trap” it somehow, like pretend to save to get the filename and then pass that on?
Generally no. When Inform asks for a filename, the result is a “fileref”, an opaque blob of data that can’t be used for anything except opening a file. The Gargoyle interpreter has a specific extension that lets Inform extract the filename from a fileref, but I don’t know if any other interpreters support that.