How To Make Energy Replenish TIme?

Hello there guys :slight_smile:

I just want to ask if how can I make a timer that when in expires it gives “Energy” like in Candy Crush

and I want to know if, how can I make the timer count event if I close the app.

Please bear with my noobness, I just started making app in Corona, and I easily learn when I do ask this kind of question, unlike reading a whole set of book, or reading the documentation.

I really appreciate your help :slight_smile:

Thank you,

Jam 

You will have to “fake” it… 

Say your user has 5 energy(the maximum)
When the user ‘uses’ a energy, save the time at which he used the energy(using os.time)
Have a timer running continously, every 1 second or so.

local function checkenergy()      local timeSince = (current time) - (time at which the user last used energy)      if timeSince \>= (time for replenishing energy) then            award the user the appopriate energy       end       end  timer.performWithdelay(1000,checkenergy,0)  

This is just a starting point. You can build upon this to your requirements.

thanks for the reply Sastheesh, :slight_smile: now  I understand how it works :slight_smile:

You will have to “fake” it… 

Say your user has 5 energy(the maximum)
When the user ‘uses’ a energy, save the time at which he used the energy(using os.time)
Have a timer running continously, every 1 second or so.

local function checkenergy()      local timeSince = (current time) - (time at which the user last used energy)      if timeSince \>= (time for replenishing energy) then            award the user the appopriate energy       end       end  timer.performWithdelay(1000,checkenergy,0)  

This is just a starting point. You can build upon this to your requirements.

thanks for the reply Sastheesh, :slight_smile: now  I understand how it works :slight_smile: