Quick Links: Gideros Home | Download Gideros | Developer Guide
Timers works wrong:( - Gideros Forums
Timers works wrong:(
  • Hello. Currently i have to use timers in my app. I was confused after that because it doesn't works as it should works. We expect events on same time every time when timer tick. But it isn't same time.
    Here it is very simple app
    timer = Timer.new(100, 10)
     
    function onTimer(e)
    print(os.timer())
     
    end
     
    timer:addEventListener(Event.TIMER, onTimer)
    timer:start()


    Os.timer() should be printed every 100ms. It is. But not every time.

    532.43867148027
    532.53866848176
    532.63867357923
    532.7386786767
    532.83868437387
    532.93868437387
    533.05472820008
    533.1547488898
    533.25475128861
    533.37170576224


    For me it is not problem now, because i check current position of sound in my app. But may be you now how to fix this?
  • OR os.timer is not "precise" as it should be >:)
    but seriously, it probably could depend on performance of the app. If app microfreezes or gets blocked for some milliseconds, timer is delayed.
  • Look at it this way.

    532.4386
    532.5386
    532.6386
    532.7386
    532.8386
    532.9386
    533.0547 <- garbage collection probably occurred
    533.1547
    533.2547
    533.3717 <- garbage collection probably occurred

    If you want that precise of a timer you probably should calculate the delta every time.
  • In your example, the difference between each timer event is about 100-110 milliseconds. This is very normal in event-driven systems. In this case, you don't expect to see exact 100 millisecond intervals.
  • atilimatilim +1 -1 (+1 / -0 )
    @ar2rsawseen :D you can't beat os.timer() :)

    Loves: duke2017

  • It is so small because of app. It is just example. When i try timers in real app(i have to show something each 500ms), there are strong assynchronization.
  • Maybe you want to register an ENTER_FRAME event and check the time with os.timer() but still in that case your precision will be 1000/60fps ~= 16ms

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID

In this Discussion

Top Posters