How to add 1 to the global variable once every 3 seconds?

Hello!
I need someone to help me. How to add 1 to the global variable once every 3 seconds?

2 ways:

  1. Use a timer. Once timer is greater than 3, increment your global variable and reset timer. On average, this is not 100% accurate as it’ll be updating the global variable a little fraction over 3 seconds every time. A more accurate way is to:

  2. Use a second global variable (var2) to keep track of time elapsed (var2 = var2 + TimeDelta()).Once it passes 3, increment your global variable, and reduce var2 by 3.

2 Likes

Thank you very much for your reply!!


I did it the way you told me, and it works perfectly!