keep track of time app is open?

Hi, I’d like to show ad to the user every 10 minutes, but it should be after 10 minutes of playing in game, not 1 minute playing and 9 minutes application in background :wink:

How would you do that? 

I would use timer.

Example

local showAdsTimer local function onTimer( event )   -- Show Ads now   print( 'Your Ads' ) end -- 10 000 ms == 10 seconds showAdsTimer = timer.performWithDelay( 10000, onTimer, 0 ) -- Whatever you need you can pause or resume timer  timer.pause( showAdsTimer ) timer.resume( showAdsTimer ) -- When you don't need timer more you have to remove it timer.cancel( showAdsTimer  )

ldurniat

To add to what @ldurniat suggested, the reason system timer is the way to go is because it sleeps when the apps sleeps.  So, sleeping won’t affect the ‘actually playing time’ measurement.

Note: timer.peformWithDelay() uses the system timer.

I would use timer.

Example

local showAdsTimer local function onTimer( event )   -- Show Ads now   print( 'Your Ads' ) end -- 10 000 ms == 10 seconds showAdsTimer = timer.performWithDelay( 10000, onTimer, 0 ) -- Whatever you need you can pause or resume timer  timer.pause( showAdsTimer ) timer.resume( showAdsTimer ) -- When you don't need timer more you have to remove it timer.cancel( showAdsTimer  )

ldurniat

To add to what @ldurniat suggested, the reason system timer is the way to go is because it sleeps when the apps sleeps.  So, sleeping won’t affect the ‘actually playing time’ measurement.

Note: timer.peformWithDelay() uses the system timer.