in my game, players have to create an account. After signing in, some important variables are stored in my database and updated whenever they are changed. When a user closes the game and reopens it, these variables are automatically set to their values in the database (which are the values that were stored in the last session).
This works perfectly. But it does only work when the user is on-line... What happens then when the user has no internet connection and the AJAX requests cannot be executed?
I tried to solve this problem, but this seems very unclean to me (and it still has some bugs):
Whenever a variable is changed, it is not only updated in the server but also in LocalStorage. There is also a LocalStorage key ("ServerUpdated") which is set to 1 (=true) when an AJAX Request or Post is executed successfully and set to 0 (=false) when there is an AJAX fail.
When the game starts, "ServerUpdated" is checked: if it is =1, variables are set to their corresponding values in the database (which should be updated, as the last season's AJAX action was successfully executed), if it is =0, variables are set to the values that were stored locally and these values are sent to the server.
This method works more or less well, but I still have some problems:
- I exported my game to Android, and after some sessions the APK's size is really big: over 22MB of additional data. This seems too big for only some variables (mainly small numbers) which are stored locally.
-What if I want to manually update a user's variable, and this user has "ServerUpdated" set to 0?
I'm sure there has to be a better way to do this, so please let me know if you have ever faced a similar problem and how you managed to solve it.
Thank you in advance