Working with Save States in iOS Shortcuts games

While experimenting with the text adventure frameworks outlined in a previous post, I became frustrated with having to start from scratch each time I re-loaded the shortcut. For shorter games, this isn’t an issue, but it prevents us from making longer experiences attractive to players. It’s not much fun to play an epic space opera adventure if you have to do it all in one sitting. So, I began playing around with the idea of implementing basic save states in a text adventure game.

To start, I made a basic layout according to the MUD-style format I outlined here: Text Adventures in iOS Shortcuts

You can download the example here:

Utilizing the “Get File” and “Save File” features, I allow the shortcut to save and receive information from iCloud Drive. In this example, I use this to create a text file with the following information:

  1. Player Class

  2. Player Position

  3. Player Inventory

  4. Amount of Gold the player has

I also put the words “Save Data” right at the top. This lets me load data using this process:

  1. Get File “filename” from iCloud Drive

  2. If file contains “Save Data”

  3. Get Text from Input

  4. Split Text by New Lines

  5. Get each item, and assign it to the proper variable.

We want to use the “Save Data” text check to verify that there is even a save file there to begin with. Otherwise, we only allow the player to start a new game. All of this is done before the main Repeat function of the game takes place, so that if we are loading a game, the player begins right where they left off. Since the loop does not particularly care where we start, no extra steps are necessary within the loop for differentiating between new or saved games.

To save the game’s progress, all you have to do is create a new Text element with the variables you want to save, in their proper order. Then pass this to the Save File function, being sure to check the “Overwrite if already exists” option. I hid this option within a couple of menus, to allow the player to start a new game and save over the previous one, but you could feasibly add the Save File function to the end of the Repeat, so that the game auto-saves after each action the player takes. It’s up to how you want things to play out.

Additionally, you’ll notice that I created a “Filename” element, and un-checked the option to “Show file selector” in both the Get File and Save File functions. This was largely an aesthetic choice for me, as I don’t much enjoy the file picker. This also allows us to ensure that the correct file is saved and loaded each time, preventing any potential errors. If you would rather let the player pick where they save/load from, just enable that option.

TylerShortcuts