How do I implement autosave?
Autosave is a feature in which a game automatically saves the player's progress at certain points without any explicit instruction to do so from the player. This is very convenient, as it completely removes the need for the player to remember to save at all, although it can have drawbacks (most obviously, it interferes with the player's ability to keep a save file at a specific point). While it's not quite as simple as some features, OHRRPGCE provides tools that can be used to create an autosave system with minimal fuss.
Extremely simple autosave script[edit]
HamsterSpeak includes a function that is actually called autosave which, when called, silently saves the game in the last-used save slot (unless no slot has been used yet, in which case it opens the save menu). You can just wrap this command in a plotscript with nothing else in it:
plotscript, perform autosave, begin autosave end
This is literally as simple as a plotscript can possibly get. But this is only half the problem!
When to autosave[edit]
Having a script to autosave is all well and good, but GAME has to know when to run it, and the answer to that question is up to you.
One option that's popular in commercial areas with autosave features is to save whenever the player enters a different area. What defines an "area" is pretty subjective, but one easy approach is to simply autosave whenever a map loads. In CUSTOM, under General Game Settings, open the General Script Triggers submenu, and set the Map autorun script to your "perform autosave" script. This will cause your game to autosave every time a map loads that doesn't have its own autorun script. If you have written autorun scripts for any of your maps, you'll have to add autosave commands to those scripts to get them to also save the game.
Another possibility is to autosave every time the player does something important in the story, like completing a quest or defeating a major boss. This is a little more complicated since there's no built-in way for GAME to know when these things happen, but if you're already using plotscripts for them, you can just add the autosave command to those scripts. You can do both this and the map autorun script, if you'd like.
If you really want to make sure your player's save file is up-to-date at all times, you can set your autosave script to run every time the hero takes a step. This works the same way as the map autorun method, but assign your script to be the "Each-Step" script instead. (Note that this will cause your game to save very frequently!) If you do this, you should probably just make the player save as soon as the game begins, unless you want the save menu to suddenly appear the first time the player takes a step.
Very slightly more complicated autosave script[edit]
You might want the game to not start autosaving until the player has actually saved once already, so that you don't end up with the save menu popping up at a weird time:
plotscript, perform autosave, begin if (last save slot) then (autosave) end
Depending on what other kinds of scripts you have in your game, you might also want to be able to disable autosaving at certain times. You might have a cutscene that involves changing maps, and you don't want the game to save in the middle of it. Or you might want to give the player the ability to turn autosave on and off using a menu or something. To let your game disable autosave, then create a tag named something like "enable autosave," and use this script for your autosave function:
plotscript, perform autosave, begin if (check tag(tag:enable autosave)) then (autosave) end
Now, you can simply set the enable autosave tag to true when you want autosaves to happen, and false when you don't.
And for completeness's sake, here's a version of the script that does both of those things:
plotscript, perform autosave, begin if (last save slot && check tag(tag:enable autosave)) then (autosave) end
Hidden autosave slot[edit]
The autosave command automatically saves to the last slot the game was saved in, which means that, if the player also has the ability to save normally, then autosaves will overwrite the player's last save file. This is fine--it's how many games with both autosave and regular save features work--but you might feel inclined to instead have a separate slot devoted specifically to autosaves. This works best if your "autosave slot" is one that's hidden because it's a higher numbered slot than the player can see. This again requires making the script a little bit more complicated:
define constant (5, autosave slot) plotscript, perform autosave, begin if (check tag(tag:enable autosave)) then, begin variable (last manual save) last manual slot := last save slot save in slot (autosave slot) set last save slot (last manual slot) end end
If you use this technique, you'll need to give the player some way to load games from this hidden slot. See How do I implement a "suspend save" feature? for information on one way of doing that. (In fact, one of the reasons you might want to keep autosaves and regular saves separate is to combine them with suspend saves, making an "oops the power went out" feature that lets the player resume from an autosave only once.)