So far in our Building Retroids series we’ve looked at detecting and handling controllers and remotes for your Amazon Fire TV game, implementing in-app purchasing to drive revenue, and how to leverage social features such as leaderboards and achievements with GameCircle. Today we are going to look at that how to implement some basic Whispersync for Games features to make your GameMaker: Studio game more convenient and fun for your players.
To the cloud!
Whispersync allows you to easily store information in the cloud—such as player progress and settings. This is convenient for your game customers who play on multiple devices or who, for whatever reason, might uninstall your game and then install it again later.
A great feature about GameCircle, which supports Whispersync, is that you don’t even need to check that your device is connected before calling the functions. Any leaderboard postings or achievement progress will be cached automatically until the device is connected.
Using Whispersync in your game
At first reading, the Whispersync documentation may make the process seems daunting and it can be confusing to translate how the Java examples in the docs will work in GameMaker. Thankfully, the GameMaker: Studio GameCircle extension makes it easy to store and retrieve numbers and strings through the Whispersync cloud. As long as your game is published on Amazon Appstore, no matter which Amazon or Android device your customer uses to play, their settings and game state is just there. If they start up your game on a Fire tablet and adjust the controls, turn off the sound and play through to level 10, and then they start your same game on their Fire TV or their Samsung Galaxy Tablet, all of those settings and their level progress can move with them. Players really appreciate this.
The first step is to think about what makes sense for you to manage in the cloud. In Retroids, I store the local high score and whether the player has unlocked premium game features. I could have also stored the currently selected graphic theme and whether the touch screen control hints are turned on. I didn't excluded these for any particular reason, it was just a choice I made when I built the game.
You’ll also need to use the information presented in the prior installment to ensure your AmazonGameCircle_InitFeatures function call includes AmazonGameCircle_Whispersync. If you are using Whispersync and Achievements, your initialization line will look like:
After defining what to store in the cloud, the next step is to determine where to put the code to actually store and retrieve those data points. In Retroids, I originally used the GameMaker INI file support to store local data. I implemented this through two scripts–scrINIWrite and scrINIRead. These became natural places in my code to add the Whispersync code. As a side note, even though we are now storing data in the cloud, I definitely recommend also caching the data locally. You don’t necessarily need to use the INI file approach, but you should cache the data in some way to provide some level of convenience for your players if they don’t have a network connection when they play your game.
To store a number to the Whispersync cloud, use the function:
This stores the current value of global variable highScore to the cloud for the current user of your game with the label “highscore”. The function AmazonGameCircle_CloudStringSet works very similarly, but is used to store a string.
After you have set your numbers and strings, in my case at the end of my scrINIWrite script, call AmazonGameCircle_CloudSynchronize(). The data would be synced with the cloud eventually, but this function gives you a way to force that to happen at the time of your choosing. I also call AmazonGameCircle_CloudSynchronize() as part of my game initialization, right after my AmazonGameCircle_InitFeatures call. This ensures I’m getting the most recent changes from the cloud on startup.
To get pull data from the cloud, you use the functions AmazonGameCircle_CloudNumberGet and AmazonGameCircle_CloudStringGet using the same names or labels you used when you saved each piece of information.
cloudScore = AmazonGameCircle_CloudNumberSet("highscore");
I mentioned that I prefer to cache the information locally in an INI file. This leads to an interesting case with the highscore. In Retroids, I get the local high score value from the INI file, then I get the cloud high score. I compare the two and set the global.highScore to the highest. This handles any possible race condition where the local value is actually higher than the cloud-saved value. You don’t want anyone to see their high score go down when they have a connection!
Depending on the requirements of your game, you can use Whispersync to store and retrieve complete game state—even the condition of the world in an RPG. Depending on the quantity and type of data you are storing, this may require that you get creative in encoding states into strings and numbers, but it is certainly possible. For storing basic data such as the settings and values, as in the examples I’ve shown in this installment, Whispersync for Games is very easy way to give your game additional polish and show your consideration for your players.
In our next installment, we’ll continue exploring GameCircle features and add Leaderboards to our game.
Miss the first six parts of the Building Retroids with GameMaker blog series?
Part 1: Studio
Part 2: Basic Controller Detection
Part 3: Handling Controllers
Part 4: Fire TV Remote and Controller Selection
Part 5: Implementing Amazon In-App Purchasing
Part 6: Implementing GameCircle