Help needed with working out amount of time lapsed between when app was last closed and reopened

I apologise in advance for being lazy and not fully reading the documentation.

I’m working on a game in which various events happen at regular time intervals. I need these events to appear to continue to happen even when the app isn’t active and open.

Without really knowing what’s available to me, I’m assuming there has to be a way of storing a timestamp when the user opens or closes the app and then by comparing these timestamps I could work out how much time has elapsed, update the various event states and make it look as if things have been happening in the background all the time.

However, various searches have failed to turn up much of use to me.

Thanks very much in advance. And sorry again for being such a n00b.

Cheers,
Andrew [import]uid: 132606 topic_id: 29486 reply_id: 329486[/import]

Forgive me if this is a mangled suggestion (I’m more of a designer than hacker), but I think that you’re not far off the mark.

The os.date() function can return various date information in the form of a table. So you could just save that information when a user opens & closes the application. Then, like you said, you would grab that information from the table and find the difference between those two dates. After you have the length of time passed, you’d just use a conditional statement to perform certain actions with the resulting number.

Perhaps someone with more experience can chime in, but that’s what I would try off the top of my head.

  • Mike [import]uid: 14700 topic_id: 29486 reply_id: 118412[/import]