Offline reward system

Basically i wanna implement offline rewards into my game, lets say the player went away for a day or 30 min they receive when they are back. Like if they went away for a day they get 50 coins and for 30min 15 coins.

You’ll need to save a timestamp to local storage when the player stops playing. When the game starts up again, read in the timestamp, use it to determine how much time has passed and what size reward to give.

1 Like

I get the idea that most apps that use this sort of thing actually just constantly run in the background (a slightly scary thought, actually), but there’s probably a way to check the time as shown by the user’s device, and then measure the time between their logging off and their logging on, but I can’t find it. There is the TimeDetector extension, but that doesn’t check the specific time, but rather month, day of week, and quarter of the day, probably so you can add seasonal events, a real-time day-night cycle, or perhaps weekend bonuses or something, rather than what you’re talking about.

I opened the TimeDetector extension in the editor to see what makes it tick. From what I’m able to understand, the time of day detection assigns a variable the value: "Time(“hour”).

Outside the extension I took a look at this. When you assign a variable a value using the editor, you can choose a selection of values from a menu. I actually had to use the search bar to find it but the value used is called “Time(String).” You can further choose from another menu what you want the value of the string to be; each value is the time value you are using at the moment. If you swap out String for “hour,” a text object displaying that variable will show you the time … in military time. The exact actual hour, that is. In military time. That’s easy to convert; if hour > 12, hour = hour - 12.

Then, yeah, pretty much what MrMen said above.

Check it this out


I mean i done tried your method but i feel like i gotten something wrong so what’s wrong?

The first event and it’s subevent are not retaining the value of LastPlayedTime, and overwriting it as soon as you load it.

Also, the third event (once the condition is corrected) will get run every game frame, around 60 times per second. You want to put that as a subevent of the beginning of scene event, so it only actions once when the game starts.

Try something along the lines of the following:

The last 2 events just check the time away and allocate coins accordingly.

Also, I don’t think hour is the correct time unit to use - it just returns the current hour.

Hold on- Do i overwrite my code to yours? I mean what if i wanted to do after like 30 min wait i give 15 coins yk? Just tryna understand

Yes, you’ll want to replace the events in your screen shot with the events from my screen shot.


That’s what the first subevent does. It checks that the number of hours passed is more than 0.5 (i.e. 30 minutes) but less than 24 hours (i.e. a day) and adds 15 coins if that’s the case.

The second subevent adds 50 coins if more than a day has passed.

For the Elapsed variable does it have to be scene variable? Got mine on global variable, idk if that’s a problem

No, the scope of variable doesn’t affect it.

However, I’ve spotted a mistake in my screen shot, brought about by me making a change and not testing it :confused: . The “Time("hour")” in the first event should be “Time("timestamp")”.

Come to think of it i thought why it wasn’t working for me however i seen it work once after i fixed it and will let u know if it works correctly afterwards
:hugs:

For some reason something is wrong it don’t seem to work, Even though i did your way.

What isn’t working? Are you waiting for at least 1/2 an hour between each time you run the game?

If you don’t want to wait that long while testing it, change the 3600000 to something smaller.

Time(“timestamp”) return time in milliseconds. To convert it to hours, it gets divided by 3,600,000. If you want smaller increments, say 1 minute time away, change the 3600000 to 60000. To make it something like 1 second time away increments, change it to 1000.

Well i will damned :joy::joy: