Multiple timers

Ok so this is a more complex question:

Is it possible to have more objects that “create” a timer that calls a function, and inside the function check which of the objects created the timer or something similar?

I also need to save the time already passed in a table when the user exit the application, is it possible?

Hi.

You can use system.getTimer() to get the time elapsed, though you might need to track a starting time, say if you come from a menu.

As for the first question, a timer -> object list should be enough for basic use. Something like this:

local TimerToObject = {} -- stuff local timer = timer.performWithDelay(1000, function(event) local handle = event.source -- handle to this timer, same as 'timer' variable outside local object = TimerToObject[handle] -- Do stuff with object, etc. TimerToObject[handle] = nil -- clean up (might need some adjustment, e.g. if the timer repeats) end) TimerToObject[timer] = MyObject

Thank you, i’ll see if i can get it working

Hi.

You can use system.getTimer() to get the time elapsed, though you might need to track a starting time, say if you come from a menu.

As for the first question, a timer -> object list should be enough for basic use. Something like this:

local TimerToObject = {} -- stuff local timer = timer.performWithDelay(1000, function(event) local handle = event.source -- handle to this timer, same as 'timer' variable outside local object = TimerToObject[handle] -- Do stuff with object, etc. TimerToObject[handle] = nil -- clean up (might need some adjustment, e.g. if the timer repeats) end) TimerToObject[timer] = MyObject

Thank you, i’ll see if i can get it working