Countdown running while the app is closed?

Hi there!

I've been looking in the forums but i didn't found something really helpful for what im searching. I want to make a countdown runing backwards when you have no lives left.

So when you have no lives, a 5 minutes countdown starts, and it doesn't matter if your app is running in the background or not, time is still counting.

I've set a countdown, but when i change scene or close the app it starts again.

Any help would be appreciated!

Thanks!😊

Comments

  • adriangomezadriangomez Member, PRO Posts: 436

    The easiest way is to record the time that the countdown starts in a variable. For example: Let us say you get a life after every 1 hour. You record 2:00 pm in the game. If the person logs in at 4:00 pm you check the variable of the last life (in this example it would be 2:00 pm) and then award the person the appropriate number of lives (in this case 2 lives).

  • I dont even know how to start doing this, i'll try!

  • adriangomezadriangomez Member, PRO Posts: 436
    1. Creat one or multiple atributes like lastDay, lastHour at the game level.
    2. Populate them with values from device.clock.day / hours / minutes depending on the timeframe you are using when they log in or grab the reward or whenever you want to gift the lives.
    3. Then next time they log or you paint the screen subtract your attribute to device.clock.day.

    Example: I will give a life after every hour for a max of 3. Player logs in and I check if attribute lastHour and lastDay is empty. If empty I populate with device.clock.hour and device.clock.day. If not empty I subtract current device.day with attribute lastDay if different I give them the max of 3 lives. If lastDay and device.day is the same. I compare lastHour with device.clock.hour. Substract one for the other and give that amount of lives up to 3.

    In a real scenario I would probably check the month also but not the year. If somebody is trying to cheat me out of lives after a year since they last played. I am ok with that. I did this from the top of my head so I might have some errors. I hope this explanation is clearer and give you a better chance of completing it.

  • Thanks again for your time @adriangomez!

    i set the timer in a different way and using tables, it works. Its a different logic but it works.

    I want to reward with 3 lives after X minutes. To do this as i told you i’m using the device time in the backgroung and i want to conect it with this countdown that i found here (this will be shown on the screen)

    i set the timer in 5 minutes, using the one that i found in the forums, but every time i change the scene, i starts again in 5 minutes.

    the problem is that i want to continue the countdown even if i change the scene.

    Any idea, i know that this is different from what i asked in the begining but it’s the only way that i know how to solve my main problem.


    thanks again!!

  • adriangomezadriangomez Member, PRO Posts: 436

    Sorry. I do not. But probably somebody else might be able to help you.

  • Dont worry i finally did it conecting our own clock with the device clock, and displaying the actor in all the scenes.

Sign In or Register to comment.