Updating real time in-game pricing and variables using Syncano

As an indie game developer attending events like PocketGamer Connects and Develop Brighton, I have noticed this trend. There are lots of services out there for indie developers, and AAA’s enabling them to manage in-game pricing of iAPs, trigger special promotions and even edit in-game functionality – all in real-time at the flick of a switch.

If you’re in the free to play mobile game industry, you will know that analytics is everything. Knowing when to sell to your users, when to offer free rewards, this stuff is priceless and can make the difference between a title with a million DAUs or a title taking $1mil per month in revenue (I am literally just guessing but you get the point).

Why do I need to change in-game pricing?

What’s the point in having products and no method to reflect their price in releation to demand? We all know about the simple pricing physcology tatics, 3.99, 6.99 and 8.99 models where 80% of users are encouraged to purchase the 6.99 price. But in todays world this just doesn’t cut it.

What I want to do is build a game that I can constantly alter, based on geo-location, national holidays and user behaviour. You name it.

How to tackle this problem in Game Maker: Studio

We need real-time access to our game, if users are dropping out after three plays because of an ad, we need to be able to change our game instantly, perhaps to show ads after 6 plays instead and you don’t have a week to wait for Apple or Google to accept your app update, it’s got to happen instantly.

We tackle this by using a real-time cloud service like Syncano. I heard about these guys because my genius of a father uses it for his app to handle data storage and so so much more.

TLDR: You can use this code to load in-game variables  and arrays from the cloud and save them onto the device for offline use.

The code – and inner workings

To make this work we’re going to create a few scripts that will allow us to have a load file on the Syncano cloud which we will load from each time the device boots up. To keep it up to date, we will save this data to the device for future use when in offline mode.

GameMaker: Studio allows for HTTP request quite nicely along with Asynchronous callbacks. For those that don’t know, an asynchronous event is one that runs outside of the GameMaker step event. It will only trigger once the HTTP request is received on the server and the server sends a callback to the device.

Setting up Syncano

First you need to sign up to Syncano – you can do that here

Once you’re signed up, you need to create an instance – let’s call it gamemaker.

Screenshot 2016-04-11 12.34.37

Click on this and then in the left sidebar navigation click on classes. You’re going to create a new class, let’s call it ‘datafile’.

Screenshot 2016-04-11 12.36.52

Under the Data Objects column, click the table next to the Zero in your ‘datafile’ class.

This will open up your database effectively. Now Syncano bills users based on datapoints and every time you make a call you use one of these. If you have 50k DAUs and everytime they open your game it’s calling this, you’re going to rack up $$$$$ per month in server costs which may be fine but let’s keep it down by being clever.

We are going to create one object that stores all of our game properties – this way we only need to make one http request per user. We can save this data to the device and even timestamp it so users only download a new datafile once every day, week, it’s up to you.Screenshot 2016-04-11 12.38.59


This is where it gets fun – click on Classes and then hit the three dot menu located on the right hand side of the ‘datafile’ class. It will open a dropdown, click edit class.

This is where we declare all of the variables, strings, integers.

Let’s create a few as an example, ‘ourVarOne’, ‘ourVarTwo’ as integers and ‘gameName’ as a string. You can also create floats (0.000s) and arrays but we will get to that another time.

Screenshot 2016-04-11 12.48.09

Now we can click on the table next to the ‘datafile’ class and view our dataobject with ID 1. It will have our variables listed in separate columns and we can click on it to edit these properties. I have put in some data for now.

Screenshot 2016-04-11 12.56.43

Right, let’s get this data into GameMaker: Studio!!

Before you do this, click on API Keys and create an API key.


Retrieving the data from our GameMaker: Studio Game

I would recommend trying this is in a new project to avoid confusion.

First we create a new object called objO. Create a ‘Create’ event and also under Asynchronous,  ‘HTTP’ event.

Screenshot 2016-04-11 12.59.36


In our create event we will paste the below code.

// This is the name of your instance in Syncano | CHANGE TO YOUR INSTANCE ID
instanceid = "gamemaker";

//This is the name of your class in Syncano | CHANGE TO YOUR CLASS NAME
class = "datafile";

// This is your API Key from Syncano| CHANGE TO YOUR API KEY

// This is the Data Object ID - If you only have one data object, the ID will be 1 for e.g.| CHANGE TO YOUR DATA OBJECT ID
objectid = "1"

// This creates the HTTP request with the ID syncGet, we will check this in the Async Event DO NOT EDIT THIS
global.syncGet = http_get("https://api.syncano.io//v1.1/instances/" + instanceid + "/classes/" + class + "/objects/" + objectid + "/?api_key=" + apikey);

//Run to show the full string in debug console 
show_debug_message("https://api.syncano.io//v1.1/instances/" + instanceid + "/classes/" + class + "/objects/" + objectid + "/?api_key=" + apikey)

What this will do is make a HTTP request with the ID of global.syncGet (I use a global incase you put the async event in a different room, it can take a while to come back if you’re on a really slow connection.

This calls your Syncano instance and will return a JSON encoded string. Now GameMaker doesn’t understand JSON, but it can decode it into a DS_Map.. GREAT SUCCESS!

So we paste this code below into the HTTP async event – this will only trigger once we get a callback from Syncano.

First it checks that the HTTP callback matches the original one we sent out – this is helpful if you have multiple HTTP requests firing and don’t want your code to be triggered by the wrong callback.

// Check that this Async Event matches the HTTP request ID syncGet
if async_load[? "id"] == global.syncGet
        // Check the HTTP request ID matches the ASYNC Event 
        // Store the JSON callback string from Syncano in a varible
        var json = async_load[? "result"]
        // To check you're getting the right JSON back you can print it to the screen.
        //Decode the JSON from the HTTP request into a DS Map called var map
        var map = json_decode(json);
        //if it doesn't load map
        if map = -1 {show_debug_message("failed to get URL")}
        /// REPLICATE THIS TO GRAB ANY FLOAT,INTEGER,STRING and store it in a ds_map
        ourVarOne = syncanoVar(map,"ourVarOne");
        // For example - this would check for a class called test2 and fill ourVariable2 with whatever is in it.
        ourVarTwo = syncanoVar(map,"ourVarTwo");
        // Get a string
        gameName = syncanoVar(map,"gameName");
        // destroy the map to avoid leaks 

There we have it. If you set everything up right you should have your three variables full of real-time data. Just log into Syncano and change the numbers, it should update instantly in your app.

I would load these variables in the create event, and if they are grabbed in the Async event, write them to the device. This way if you have no internet connection, your device will load the most recent datafile downloaded.


Here are a few ideas I have used this for.

  • Running various game code versions – say you have three different methods of gameplay you want to test. Create a variable, either 1,2 or 3, put in a switch statement and boom. You can select which version you want to run in you Data Object on Syncano and it will update in game.
  • Geo-Located pricing.
    • Let’s say you have three iAPs. 10, 100 and 1000 coins. You can’t change the iAP price easily, but you could make it 20, 200 or 2000 coins.
    • Create a new dataobject for each of your regions, their object ID will be 1,2,3,4,5, etc. Create three variables, purchase1,purchase2,purchase3.
    • You can grab regionCode on your device using a HTTP request to http://ip-api.com/json
    • Decode the JSON, load it into a DS map the same way as done above.
    • Now you can make some code that will change the ‘objectid’ we use in our HTTP request from Syncano depending on what the region code is.
    • ‘if regionCode = GB {objectid = 3} for example.
  • Personally I store 20 variables that effect the game play, how often ads show in game, pricing, rewards, I even have code that will allow me to turn a variable to true and initiate a special offer.

Feel free to drop me any questions below and have fun making your game even more dynamic with updatable, online storage using Syncanos real-time cloud.

Recommended Posts