Synchronizing player currency (not score) over multiple devices – using a cloud

I was building a racing game which uses a fake currency. The player receives money when winning races, money that he can use to buy new cars or unlock new tracks.

But what if the player was playing during the day on his phone, and at night on a tablet? I wanted the progress to be synchronized.


The solution is simple when synchronising a game that has a score that only goes up (incremented in only one direction).

if (scoreInCloud > scoreInDevice)



    scoreInDevice = scoreInCloud;



              scoreInCloud = scoreInDevice;


This says that we always use the biggest score to decide if you upload the score to the cloud or if you download from the cloud.


But with currency the problem is trickier. We don’t have “the biggest currency”. The player can have 5000 money on one device, 5000 in the cloud, and 7000 on the tablet. How do you tell the tablet to update the money to 5000?


I first thought using timestamps to keep track on which info was the most recent. But that only complicates things, and didn’t solved the problem.

After going back to the drawing board, I came up with this solution: I use a versioning system. (duh)


When I upload the money value to the cloud, I also send a version:

Player X has 5000 money (version 3).

On the second device I can have 7000 money with version 2. I do a version comparison to decide if I upload or download to the cloud:

if (versionInCloud > versionInDevice)



    moneyInDevice = moneyInCloud;

} else {


                  moneyInCloud = moneyInDevice;


Which translates to: get the money from the cloud if the version in the cloud is bigger than the one on the device, and vice versa.


Share this info with your audience:
Was this helpful?

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Buy me a coffee