Hi! I've searched around for quite a while already and I couldn't find any answers. I'm currently making a clicker/idle game, and I want to make it to where the player can generate points even when they're not on the app. Any help would be appreciated. Thanks!
Run a timer in the background, with timerAlwaysFires set to
true, in conjunction with the Background Tasks extension.
If the app doesn't close but is just in background or idle mode, you need to use a Foreground service so that the timer stays active also in the background.
Assuming the points are to be kept locally on the phone, you can simulate all that with a little TinyDB record keeping and some startup code.
- Keep a TinyDB tag/value LASTScoreMS / the Clock1.SystemTime milliseconds when you last scored a point
- At startup, calculate downtime_ms = (Clock1.SystemTime - the TinyDB value from tag LASTScoreMS (Only do this if tag found, otherwise you would try to pay for downtime since 1970). Take downtime milliseconds, and calculate how many points should have been earned over that time interval using arithmetic.
That's what I was looking for! Thanks!
Well, now I have a new problem: the downtime calculations work great, but whenever I enter the "Shop" screen specifically, it resets my score back to 1.
Show us the Shop screen?
Also, see How to Switch Screens in
I see lots of places in the Shop screen where you subtract ever increasing values from the Score.
Are you buying things?
Also, check your TinyDB1 NameSpace for consistency among your screens, to insure you are passing the same data among screens.
You can avoid lots of confusion by encapsulating values in setter/getter procedures that manipulate TinyDB behind the scenes, hiding tags and updates from the rest of your code and avoiding the burden of keeping global variables in sync with TinyDB.
Yes, the subtraction is meant for buying shop items. I checked and the tinydb seems pretty consistent.
Use the Do It facility to trace where the score in TinyDB changes.
I would like to understand the game. So when are points awarded and for what when the app is in the background?
Basically, it's a simple clicker game in which the player increases their score by clicking a button. They can spend their points by buying various things in the shop which increases their multiplier (granting increased clicks per click). I would like to also add offline multipliers in the shop which allow the user to generate points when they are not in the game.
How can the player click a button (and increase / generate points) when the game (app) is in the background?
Well, I wanted to make it to where for every second the user is offline, that amount is multiplied by their offline multiplier. So the user isn’t clicking a button for points, it’s just automatically given to them based on a few calculations.
Also, I think I found the problem. The variable “Score” is in both the Home Screen and the Shop screen. I changed the variable in the Shop screen to “score_shop” and my problem seems to be resolved after a lot of testing.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.