How to make my timer tick as fast as system clock?

I’ve been reading and what I got from those is that timer always runs slower than the system clock. This is because of the way App inventor or kodular works. Isn’t there a way to make the timers sync with system clock (which is probably synced to Network Clock)? Or am I fated to have lagging timers compared to system clock?

Is not like the timer is slower really. The problem is it takes some time to process and update the screen and do everything you need to do until the actual time is shown to the user. So those few milliseconds it takes to do that are what makes the times be different.

There’s some workarounds, but it depends on what kind of app you are doing. Care to explain what is your project about?

1 Like

My difference really is not in milliseconds. But as time passes, the difference between system clock and my timers get bigger. I am trying to make something now to prove my point, and it would be simpler than demonstrating it using my project. Please give me sometime, because I am quite new.

1 Like

That’s exactly what I meant. The little increments in 2-10 ms amount to more and more as time passes if you use a cumulative system.
But if you just “consult” the clock and make a calculation, then the time shown is more accurate.

Example, you only save the starting milliseconds. Set a clock to trigger every second (1000 ms). In the Clock.Timer event just subtract the current millisecond in time to the starting one. That way you are not accumulating those extra milliseconds that it takes to process everything internally.

3 Likes

Ah I see. I will try that. Thank you so much. I will post back after I do it. Thank you.
But will the time difference always be that constant? If it fluctuates, eventually, the difference can accumulate too, whichever way it plans to go right?

2 Likes


As promised. The program… I haven’t tried your suggestion yet.

But will the time difference always be that constant? If it fluctuates, eventually, the difference can accumulate too, whichever way it plans to go right?

Ok, I see you are accumulating the seconds in a variable. Instead of that, make it so you only show the difference between the starting time and the current time. That will always give you an accurate time relative to the device’s time.

1 Like

Clock.Minute, Clock.Second etc may has a delay because parsing can take some milliseconds (even it looks instantly). Maybe you can reach to the system clock by only displaying instant. I know you won’t able to read minute and second from an instant, but at least you will reduce task time.

1 Like

Thank you guys for your suggestions. I will try them out.

I face the similar problem (countdown from timer). Might I post it here instead of opening a new topic?

Yes, if it’s exactly the same problem, I guess it’s ok to do it here.
Have you read the previous suggestions? Did you try those?

1 Like

Hi co-koders,

I am also trying to set a clock countdown from 10 minutes to 0.
I followed the @Italo suggestion to only show the difference of starting and ending times.
Furthermore, I avoid extract min and sec from an instance which may be time consuming as @yusufcihan posted.

The inconsistency I get is that time of 10 min is consumed very quick. It completes in less than 60 s.

What I coded here is here:
When touching btAction, TimeRunning is set to true and StartT gets instant in ms since 1970.
As Clock1.Timer is activated new instant is getting repeatedly, saved to EndT.
The difference EndT-StartT is passed to DeltaT and TimeLeft is reduced by DeltaT.
The demand is to display TimeLeft.

PS.
Added aia to facilitate checking
test_2.aia (36.9 KB)

1 Like

Hi to the community,

Trying some other alternatives, I finally managed my aim. A countdown code to display time allowing intermediate start/stop intervals. It might be useful to @yulius or anyone else.

Please note the following:

  1. Normally min:sec is displayed. When time left is less than 1s, then sec:hundreds is shown.
  2. It is for demontration purposes to quickly reach 60s. So var PeriodTime is set to 2 min. Set it accordingly (eg 600000 for a basketball period).
  3. A strPadL procedure is used to display single digit seconds as zero-preceded (like 09).
  4. In the part else if global TimeLeft < 0 a correction display set Label2.Text to 0:00 is added, since sometimes a few hundreds of sec remain in time counting after execution.

I upload both blocks and aia.


test_3.aia (37.1 KB)

4 Likes

Thanks for posting your solution. It will be a valuable reference for others with the same needs. :+1:

5 Likes

Thank you so much for your solutions guys!!

2 Likes

By mistake, a block set Clock1.TimerInterval to 1000 positioned in when Clock2.Timer, should read Clock2. Timer1 is needless.
Good luck to your project.

2 Likes

Thank you so much !! :grin:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.