Hello!
I need someone to help me. How to add 1 to the global variable once every 3 seconds?
2 ways:
-
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:
-
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