[RESOLVED] How to have a continous timer when App is not running in background or multitask list?

Hello

I hope the title explains it. Ok so I’ve been trying to figure how I can a timer that will continue running even when the user has removed the app from multitasking list or is not in background or suspended you know what I mean? So basically what I’m trying to achieve here is have the a timer continuously running even when the app is not at multitask list or in background for the user to still be notify when example to feed your virtual pet or something?

Can this be done with Pro or it has to be Enterprise?

Here is a good post about working with time http://www.coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/

So basically just use os.time() whenever you need the current time.

You need to be able to save the time when you last fed your pet. You can save a json file as your persistent storage method or use SQLite. Something ready made like GGdata (using json) will make things easier, https://github.com/GlitchGames/GGData

Doesn’t that mean someone could just change the time on their device to finish whatever task was started instantly?

Then you need to get time from somewhere externally. Have to think about if its really worth the effort. Personally if its a single player game with no online leaderboard I wouldn’t care if someone want’s to ruin their gaming experience like that. 

Should be easy enough to find an online time service though, like this one: http://json-time.appspot.com/time.json or something more reliable: http://developer.yahoo.com/util/timeservice/V1/getTime.html

This is what I have so far

local lastMove = GGData:new( "sample" ) lastMove:set( "message", "hello, world" ) print( lastMove:get( "anotherValue" ) ) print( lastMove.message ) local now = os.time() local function checkit() if ( lastMove.anotherValue + 5 \>= now + 10 ) then -- nudge the player local text = display.newText("GOOD", 0,0,"Arial", 20) text.x = display.contentWidth / 2 text.y = display.contentHeight / 2 text:setTextColor(0,255,0) end end local function tik() lastMove.anotherValue = os.time() lastMove.anotherValue = lastMove.anotherValue lastMove:save() print(lastMove:get( "anotherValue" )) checkit() lastMove:save() end timer.performWithDelay(1000, tik, 0)

It works when after 5 seconds it would show the text “Good”, but I’m unable to figure out how do I have the text stay on the screen when the App has been killed from the background or when I reset the simulator.

EDIT: Never mind I got what I did was use a boolean so basically it would be true if seconds has passed. Once is true the boolean would be save making the text still be there because the value is true if is false it goes away.

Thank you very much for pointing me to the right the directions.

Here is a good post about working with time http://www.coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/

So basically just use os.time() whenever you need the current time.

You need to be able to save the time when you last fed your pet. You can save a json file as your persistent storage method or use SQLite. Something ready made like GGdata (using json) will make things easier, https://github.com/GlitchGames/GGData

Doesn’t that mean someone could just change the time on their device to finish whatever task was started instantly?

Then you need to get time from somewhere externally. Have to think about if its really worth the effort. Personally if its a single player game with no online leaderboard I wouldn’t care if someone want’s to ruin their gaming experience like that. 

Should be easy enough to find an online time service though, like this one: http://json-time.appspot.com/time.json or something more reliable: http://developer.yahoo.com/util/timeservice/V1/getTime.html

This is what I have so far

local lastMove = GGData:new( "sample" ) lastMove:set( "message", "hello, world" ) print( lastMove:get( "anotherValue" ) ) print( lastMove.message ) local now = os.time() local function checkit() if ( lastMove.anotherValue + 5 \>= now + 10 ) then -- nudge the player local text = display.newText("GOOD", 0,0,"Arial", 20) text.x = display.contentWidth / 2 text.y = display.contentHeight / 2 text:setTextColor(0,255,0) end end local function tik() lastMove.anotherValue = os.time() lastMove.anotherValue = lastMove.anotherValue lastMove:save() print(lastMove:get( "anotherValue" )) checkit() lastMove:save() end timer.performWithDelay(1000, tik, 0)

It works when after 5 seconds it would show the text “Good”, but I’m unable to figure out how do I have the text stay on the screen when the App has been killed from the background or when I reset the simulator.

EDIT: Never mind I got what I did was use a boolean so basically it would be true if seconds has passed. Once is true the boolean would be save making the text still be there because the value is true if is false it goes away.

Thank you very much for pointing me to the right the directions.