Storing dates with limited datatypes. Any suggestions?

Hello, I have recently made a list of achievements to add to my game in order to engage users to play more frequently. Most of them are easily detected such as when the user have collected x amount of coins he/she will acquire the “gold digger” achievement etc… However I’m having trouble thinking of a cleaver way to detect another achievement which is acquired if the user plays the game 7 days in a row.

Normally I would add Date.now to an array each time the user logs into the game, I would probably also check if ( dateArray[last] = today ), then not add a new day to prevent duplicate days. This would keep a nice track of which days the user was active, and I could check if the last 7 array dates had no gaps and then unlock the achievement. But since I’m using an external tool to manage persistence across different platforms I have limited options as to which data types are allowed to be persisted, and if fact it doesn’t seem to ship with any kin of collect/lists.

The tool is called CloudOnce and is a very nice google play services integration, and also support apple and amazon cloud thingies.

Here is my options:

I’m scripting in C#. Any suggestions on how to validate the 7 day achievement rules with any of the data types above. (I cannot dynamically generate these persistence variables, they are manually setup in the UI)

Storing an array would fail if they logged in mutliple times a day. You really only need to store one time: the time when their streak started. Every time they log in, compare the current date/time to the stored streak. If it’s longer than 7 days, set that as the streak start date. If you need an UI update for “only 3 days to go!” you can calculate that from the current date/time and the start of the streak as well.

If you need to store the data as an integer, convert it to Unix time: Unix time - Wikipedia

Good point. And if stored date and current dates’ delta is more than one day, I reset the stored date to current date wich will restart the “days in row” count. Thanks

Oops – you’ll need to store the number of days in a row too and reset it to 0 if the span is greater than 24 hours, then log the current date as the last login date. Good catch.

Yeah, but 24 hours check won’t do the trick. If a user logs in today 7th October, at 14:00 and then logs in the day after 8th of October at 22:00. That is more that 24 hours apart (32 hours), but still the next day.